MUSA Runtime API Reference
1. Introduction
The MUSA Runtime API is the application-level musa* interface for device, memory, stream, event, execution, graph, and interoperability operations.
This reference describes the MUSA Runtime APIs supported in MUSA SDK 5.2.0. Use it as the compatibility reference for the functions, types, structures, fields, constants, and status values documented here.
Note: Some Runtime 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 Runtime API
Use the Runtime API as the default application-facing interface. Use the Driver API when you need lower-level mu* control over contexts, modules, entry points, or Driver-owned objects.
Runtime entries may cross-reference Driver APIs when the two layers expose related behavior. When mixing layers, check the context, stream, and object ownership rules in the relevant function entries before passing handles between 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 Runtime version checks. Use Interactions with the MUSA Driver API when a Runtime entry interacts with Driver-level objects.
3. Modules
The API reference is organized by capability module.
Module List
- 3.1 Profiler Control
- 3.2 Device Management
- 3.3 Device Management [DEPRECATED]
- 3.4 Thread Management [DEPRECATED]
- 3.5 Error Handling
- 3.6 Stream Management
- 3.7 Event Management
- 3.8 External Resource Interoperability
- 3.9 Execution Control
- 3.10 Execution Control [DEPRECATED]
- 3.11 Occupancy
- 3.12 Memory Management
- 3.13 Memory Management [DEPRECATED]
- 3.14 Stream Ordered Memory Allocator
- 3.15 Unified Addressing
- 3.16 Peer Device Memory Access
- 3.17 Graphics Interoperability
- 3.18 Texture Reference Management [DEPRECATED]
- 3.19 Surface Reference Management [DEPRECATED]
- 3.20 Texture Object Management
- 3.21 Surface Object Management
- 3.22 Version Management
- 3.23 Graph Management
- 3.24 Driver Entry Point Access
- 3.25 Library Management
- 3.26 Error Log Management
- 3.27 Interactions with the MUSA Driver API
- 3.28 Memory Atomic Management
3.1 Profiler Control
musaProfilerStart
musaError_t musaProfilerStart(void)
Description
- Enable profiling.
- Enables profile collection by the active profiling tool for the current context. If profiling is already enabled, then musaProfilerStart() has no effect.
- musaProfilerStart and musaProfilerStop APIs are used to programmatically control the profiling granularity by allowing profiling to be done only on selective pieces of code.
Parameters
(unnamed)(void)
Returns
- musaSuccess
Note
- This function may also return error codes from previous, asynchronous launches.
See also
musaProfilerStop
musaError_t musaProfilerStop(void)
Description
- Disable profiling.
- Disables profile collection by the active profiling tool for the current context. If profiling is already disabled, then musaProfilerStop() has no effect.
- musaProfilerStart and musaProfilerStop APIs are used to programmatically control the profiling granularity by allowing profiling to be done only on selective pieces of code.
Parameters
(unnamed)(void)
Returns
- musaSuccess
Note
- This function may also return error codes from previous, asynchronous launches.
See also
3.2 Device Management
musaDeviceReset
musaError_t musaDeviceReset(void)
Description
- Destroy all allocations and reset all state on the current device in the current process.
- Explicitly destroys and cleans up all resources associated with the current device in the current process. It is the caller's responsibility to ensure that the resources are not accessed or passed in subsequent API calls and doing so will result in undefined behavior. These resources include MUSA types musaStream_t, musaEvent_t, musaArray_t, musaMipmappedArray_t, musaPitchedPtr, musaTextureObject_t, musaSurfaceObject_t, textureReference, surfaceReference, musaExternalMemory_t, musaExternalSemaphore_t and musaGraphicsResource_t. These resources also include memory allocations by musaMalloc, musaMallocHost, musaMallocManaged and musaMallocPitch. Any subsequent API call to this device will reinitialize the device.
- Note that this function will reset the device immediately. It is the caller's responsibility to ensure that the device is not being accessed by any other host threads from the process when this function is called.
Parameters
(unnamed)(void)
Returns
- musaSuccess
Note
- musaDeviceReset() will not destroy memory allocations by musaMallocAsync() and musaMallocFromPoolAsync(). These memory allocations need to be destroyed explicitly.
- If a non-primary MUcontext is current to the thread, musaDeviceReset() will destroy only the internal MUSA RT state for that MUcontext.
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
See also
musaDeviceSynchronize
musaError_t musaDeviceSynchronize(void)
Description
- Wait for compute device to finish.
- Blocks until the device has completed all preceding requested tasks. musaDeviceSynchronize() returns an error if one of the preceding tasks has failed. If the musaDeviceScheduleBlockingSync flag was set for this device, the host thread will block until the device has finished its work.
Parameters
(unnamed)(void)
Returns
- musaSuccess
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
- This API is deprecated for device-wide synchronization control.
See also
musaDeviceSetLimit
musaError_t musaDeviceSetLimit(enum musaLimit limit, size_t value)
Description
- Set resource limits.
- Setting limit to value is a request by the application to update the current limit maintained by the device. 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 musaDeviceGetLimit() to find out exactly what the limit has been set to.
- Setting each musaLimit has its own specific restrictions, so each is discussed here.
- musaLimitStackSize controls the stack size in bytes of each GPU thread. musaLimitPrintfFifoSize controls the size in bytes of the shared FIFO used by the printf() device system call. Setting musaLimitPrintfFifoSize must not be performed after launching any kernel that uses the printf() device system call - in such case musaErrorInvalidValue will be returned. musaLimitMallocHeapSize controls the size in bytes of the heap used by the malloc() and free() device system calls. Setting musaLimitMallocHeapSize must not be performed after launching any kernel that uses the malloc() or free() device system calls - in such case musaErrorInvalidValue will be returned. musaLimitDevRuntimeSyncDepth 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 runtime to reserve large amounts of device memory which can no longer be used for user allocations. If these reservations of device memory fail, musaDeviceSetLimit will return musaErrorMemoryAllocation, 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 will results in error musaErrorUnsupportedLimit being returned. musaLimitDevRuntimePendingLaunchCount controls the maximum number of outstanding device runtime launches that can be made from the current device. 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 runtime to reserve larger amounts of device memory upfront which can no longer be used for allocations. If these reservations fail, musaDeviceSetLimit will return musaErrorMemoryAllocation, 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 musaErrorUnsupportedLimit being returned. musaLimitMaxL2FetchGranularity 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. musaLimitPersistingL2CacheSize 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(enum musaLimit): Limit to setvalue(size_t): Size of limit
Returns
- musaSuccess, musaErrorUnsupportedLimit, musaErrorInvalidValue, musaErrorMemoryAllocation
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
See also
musaDeviceGetLimit
musaError_t musaDeviceGetLimit(size_t *pValue, enum musaLimit limit)
Description
- Return resource limits.
- Returns in *pValue the current size of limit. The following musaLimit values are supported. musaLimitStackSize is the stack size in bytes of each GPU thread. musaLimitPrintfFifoSize is the size in bytes of the shared FIFO used by the printf() device system call. musaLimitMallocHeapSize is the size in bytes of the heap used by the malloc() and free() device system calls. musaLimitDevRuntimeSyncDepth is the maximum grid depth at which a thread can isssue the device runtime call musaDeviceSynchronize() to wait on child grid launches to complete. This functionality is removed for devices of compute capability >= 9.0, and hence will return error musaErrorUnsupportedLimit on such devices. musaLimitDevRuntimePendingLaunchCount is the maximum number of outstanding device runtime launches. musaLimitMaxL2FetchGranularity is the L2 cache fetch granularity. musaLimitPersistingL2CacheSize is the persisting L2 cache size in bytes.
Parameters
pValue(size_t *): Returned size of the limitlimit(enum musaLimit): Limit to query
Returns
- musaSuccess, musaErrorUnsupportedLimit, musaErrorInvalidValue
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
See also
musaDeviceGetTexture1DLinearMaxWidth
musaError_t musaDeviceGetTexture1DLinearMaxWidth(size_t *maxWidthInElements, const struct musaChannelFormatDesc *fmtDesc, int device)
Description
- Returns the maximum number of elements allocatable in a 1D linear texture for a given element size.
- Returns in maxWidthInElements the maximum number of elements allocatable in a 1D linear texture for given format descriptor fmtDesc.
Parameters
maxWidthInElements(size_t *): Returns maximum number of texture elements allocatable for given fmtDesc.fmtDesc(const struct musaChannelFormatDesc *): Texture format description.device(int)
Returns
- musaSuccess, musaErrorUnsupportedLimit, musaErrorInvalidValue
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
See also
musaDeviceGetCacheConfig
musaError_t musaDeviceGetCacheConfig(enum musaFuncCache *pCacheConfig)
Description
- Returns the preferred cache configuration for the current device.
- On devices where the L1 cache and shared memory use the same hardware resources, this returns through pCacheConfig the preferred cache configuration for the current device. This is only a preference. The runtime 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 pCacheConfig of musaFuncCachePreferNone on devices where the size of the L1 cache and shared memory are fixed.
- The supported cache configurations are: musaFuncCachePreferNone: no preference for shared memory or L1 (default) musaFuncCachePreferShared: prefer larger shared memory and smaller L1 cache musaFuncCachePreferL1: prefer larger L1 cache and smaller shared memory musaFuncCachePreferEqual: prefer equal size L1 cache and shared memory
Parameters
pCacheConfig(enum musaFuncCache *): Returned cache configuration
Returns
- musaSuccess
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
See also
- musaDeviceSetCacheConfig, musaFuncSetCacheConfig (C API), musaFuncSetCacheConfig (C++ API), muCtxGetCacheConfig
musaDeviceGetStreamPriorityRange
musaError_t musaDeviceGetStreamPriorityRange(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 the meaningful range as specified by this API, the priority is automatically clamped down or up to either *leastPriority or *greatestPriority respectively. See musaStreamCreateWithPriority 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 musaDeviceGetAttribute).
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
- musaSuccess
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
See also
musaDeviceSetCacheConfig
musaError_t musaDeviceSetCacheConfig(enum musaFuncCache cacheConfig)
Description
- Sets the preferred cache configuration for the current device.
- On devices where the L1 cache and shared memory use the same hardware resources, this sets through cacheConfig the preferred cache configuration for the current device. This is only a preference. The runtime 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 musaFuncSetCacheConfig (C API) or musaFuncSetCacheConfig (C++ API) will be preferred over this device-wide setting. Setting the device-wide cache configuration to musaFuncCachePreferNone 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: musaFuncCachePreferNone: no preference for shared memory or L1 (default) musaFuncCachePreferShared: prefer larger shared memory and smaller L1 cache musaFuncCachePreferL1: prefer larger L1 cache and smaller shared memory musaFuncCachePreferEqual: prefer equal size L1 cache and shared memory
Parameters
cacheConfig(enum musaFuncCache): Requested cache configuration
Returns
- musaSuccess
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
See also
- musaDeviceGetCacheConfig, musaFuncSetCacheConfig (C API), musaFuncSetCacheConfig (C++ API), muCtxSetCacheConfig
musaDeviceGetByPCIBusId
musaError_t musaDeviceGetByPCIBusId(int *device, const char *pciBusId)
Description
- Returns a handle to a compute device.
- Returns in *device a device ordinal given a PCI bus ID string.
Parameters
device(int *): Returned device ordinalpciBusId(const char *): String in one of the following forms:
Returns
- musaSuccess, musaErrorInvalidValue, musaErrorInvalidDevice
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
See also
musaDeviceGetPCIBusId
musaError_t musaDeviceGetPCIBusId(char *pciBusId, int len, int device)
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 namedevice(int): Device to get identifier string for
Returns
- musaSuccess, musaErrorInvalidValue, musaErrorInvalidDevice
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
See also
musaIpcGetEventHandle
musaError_t musaIpcGetEventHandle(musaIpcEventHandle_t *handle, musaEvent_t 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 musaEventInterprocess and musaEventDisableTiming flags set. This opaque handle may be copied into other processes and opened with musaIpcOpenEventHandle to allow efficient hardware synchronization between GPU work in different processes.
- After the event has been been opened in the importing process, musaEventRecord, musaEventSynchronize, musaStreamWaitEvent and musaEventQuery may be used in either process. Performing operations on the imported event after the exported event has been freed with musaEventDestroy 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 musaDeviceGetAttribute with musaDevAttrIpcEventSupport
Parameters
handle(musaIpcEventHandle_t *): Pointer to a user allocated musaIpcEventHandle in which to return the opaque event handleevent(musaEvent_t): Event allocated with musaEventInterprocess and musaEventDisableTiming flags.
Returns
- musaSuccess, musaErrorInvalidResourceHandle, musaErrorMemoryAllocation, musaErrorMapBufferObjectFailed, musaErrorNotSupported, musaErrorInvalidValue
Note
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
See also
- musaEventCreate, musaEventDestroy, musaEventSynchronize, musaEventQuery, musaStreamWaitEvent, musaIpcOpenEventHandle, musaIpcGetMemHandle, musaIpcOpenMemHandle, musaIpcCloseMemHandle, muIpcGetEventHandle
musaIpcOpenEventHandle
musaError_t musaIpcOpenEventHandle(musaEvent_t *event, musaIpcEventHandle_t handle)
Description
- Opens an interprocess event handle for use in the current process.
- Opens an interprocess event handle exported from another process with musaIpcGetEventHandle. This function returns a musaEvent_t that behaves like a locally created event with the musaEventDisableTiming flag specified. This event must be freed with musaEventDestroy.
- Performing operations on the imported event after the exported event has been freed with musaEventDestroy 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 musaDeviceGetAttribute with musaDevAttrIpcEventSupport
Parameters
event(musaEvent_t *): Returns the imported eventhandle(musaIpcEventHandle_t): Interprocess handle to open
Returns
- musaSuccess, musaErrorMapBufferObjectFailed, musaErrorNotSupported, musaErrorInvalidValue, musaErrorDeviceUninitialized
Note
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
See also
- musaEventCreate, musaEventDestroy, musaEventSynchronize, musaEventQuery, musaStreamWaitEvent, musaIpcGetEventHandle, musaIpcGetMemHandle, musaIpcOpenMemHandle, musaIpcCloseMemHandle, muIpcOpenEventHandle
musaIpcGetMemHandle
musaError_t musaIpcGetMemHandle(musaIpcMemHandle_t *handle, void *devPtr)
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 musaMalloc 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 musaFree and a subsequent call to musaMalloc returns memory with the same device address, musaIpcGetMemHandle 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 musaDeviceGetAttribute with musaDevAttrIpcEventSupport
Parameters
handle(musaIpcMemHandle_t *): Pointer to user allocated musaIpcMemHandle to return the handle in.devPtr(void *): Base pointer to previously allocated device memory
Returns
- musaSuccess, musaErrorMemoryAllocation, musaErrorMapBufferObjectFailed, musaErrorNotSupported, musaErrorInvalidValue
Note
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
See also
- musaMalloc, musaFree, musaIpcGetEventHandle, musaIpcOpenEventHandle, musaIpcOpenMemHandle, musaIpcCloseMemHandle, muIpcGetMemHandle
musaIpcOpenMemHandle
musaError_t musaIpcOpenMemHandle(void **devPtr, musaIpcMemHandle_t 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 musaIpcGetMemHandle into the current device address space. For contexts on different devices musaIpcOpenMemHandle can attempt to enable peer access between the devices as if the user called musaDeviceEnablePeerAccess. This behavior is controlled by the musaIpcMemLazyEnablePeerAccess flag. musaDeviceCanAccessPeer can determine if a mapping is possible.
- musaIpcOpenMemHandle can open handles to devices that may not be visible in the process calling the API.
- Contexts that may open musaIpcMemHandles are restricted in the following way. musaIpcMemHandles from each device in a given process may only be opened by one context per device 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 musaIpcOpenMemHandle must be freed with musaIpcCloseMemHandle.
- Calling musaFree on an exported memory region before calling musaIpcCloseMemHandle 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 musaDeviceGetAttribute with musaDevAttrIpcEventSupport
Parameters
devPtr(void **): Returned device pointerhandle(musaIpcMemHandle_t): musaIpcMemHandle to openflags(unsigned int): Flags for this operation. Must be specified as musaIpcMemLazyEnablePeerAccess
Returns
- musaSuccess, musaErrorMapBufferObjectFailed, musaErrorInvalidResourceHandle, musaErrorDeviceUninitialized, musaErrorTooManyPeers, musaErrorNotSupported, musaErrorInvalidValue
Note
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
- No guarantees are made about the address returned in *devPtr. In particular, multiple processes may not receive the same address for the same handle.
See also
- musaMalloc, musaFree, musaIpcGetEventHandle, musaIpcOpenEventHandle, musaIpcGetMemHandle, musaIpcCloseMemHandle, musaDeviceEnablePeerAccess, musaDeviceCanAccessPeer, muIpcOpenMemHandle
musaIpcCloseMemHandle
musaError_t musaIpcCloseMemHandle(void *devPtr)
Description
- Attempts to close memory mapped with musaIpcOpenMemHandle.
- Decrements the reference count of the memory returnd by musaIpcOpenMemHandle 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 musaDeviceGetAttribute with musaDevAttrIpcEventSupport
Parameters
devPtr(void *): Device pointer returned by musaIpcOpenMemHandle
Returns
- musaSuccess, musaErrorMapBufferObjectFailed, musaErrorNotSupported, musaErrorInvalidValue
Note
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
See also
- musaMalloc, musaFree, musaIpcGetEventHandle, musaIpcOpenEventHandle, musaIpcGetMemHandle, musaIpcOpenMemHandle, muIpcCloseMemHandle
musaDeviceRegisterAsyncNotification
musaError_t musaDeviceRegisterAsyncNotification(int device, musaAsyncCallback callbackFunc, void *userData, musaAsyncCallbackHandle_t *callback)
Description
- Blocks until remote writes are visible to the specified scope.
- Blocks until remote writes to the target context via mappings created through GPUDirect RDMA APIs, like mthreads_p2p_get_pages (see https://docs.mthreads.com/musa/gpudirect-rdma for more information), are visible to the specified scope.
- If the scope equals or lies within the scope indicated by musaDevAttrGPUDirectRDMAWritesOrdering, the call will be a no-op and can be safely omitted for performance. This can be determined by comparing the numerical values between the two enums, with smaller scopes having smaller values.
- Users may query support for this API via musaDevAttrGPUDirectRDMAFlushWritesOptions.
- Registers callbackFunc to receive async notifications.
- The userData parameter is passed to the callback function at async notification time. Likewise, callback is also passed to the callback function to distinguish between multiple registered callbacks.
- The callback function being registered should be designed to return quickly (~10ms). Any long running tasks should be queued for execution on an application thread.
- Callbacks may not call musaDeviceRegisterAsyncNotification or musaDeviceUnregisterAsyncNotification. Doing so will result in musaErrorNotPermitted. Async notification callbacks execute in an undefined order and may be serialized.
- Returns in *callback a handle representing the registered callback instance.
Parameters
device(int): The device on which to register the callbackcallbackFunc(musaAsyncCallback): The function to register as a callbackuserData(void *): A generic pointer to user data. This is passed into the callback function.callback(musaAsyncCallbackHandle_t *): A handle representing the registered callback instance
Returns
- musaSuccess, musaErrorNotSupported
- musaSuccess musaErrorNotSupported musaErrorInvalidDevice musaErrorInvalidValue musaErrorNotPermitted musaErrorUnknown
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
See also
- muFlushGPUDirectRDMAWrites
- musaDeviceUnregisterAsyncNotification
musaDeviceUnregisterAsyncNotification
musaError_t musaDeviceUnregisterAsyncNotification(int device, musaAsyncCallbackHandle_t callback)
Description
- Unregisters an async notification callback.
- Unregisters callback so that the corresponding callback function will stop receiving async notifications.
Parameters
device(int): The device from which to remove callback.callback(musaAsyncCallbackHandle_t): The callback instance to unregister from receiving async notifications.
Returns
- musaSuccess musaErrorNotSupported musaErrorInvalidDevice musaErrorInvalidValue musaErrorNotPermitted musaErrorUnknown
Note
- This function may also return error codes from previous, asynchronous launches.
See also
musaGetDeviceCount
musaError_t musaGetDeviceCount(int *count)
Description
- Returns the number of compute-capable devices.
- Returns in *count the number of devices with compute capability greater or equal to 2.0 that are available for execution.
Parameters
count(int *): Returns the number of devices with compute capability greater or equal to 2.0
Returns
- musaSuccess
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
See also
- musaGetDevice, musaSetDevice, musaGetDeviceProperties, musaChooseDevice, musaInitDevice, muDeviceGetCount
musaGetDeviceProperties
musaError_t musaGetDeviceProperties(struct musaDeviceProp *prop, int device)
Description
- Returns information about the compute-device.
- Returns in *prop the properties of device dev. The musaDeviceProp structure is defined as:
struct musaDeviceProp {
char name[256];
musaUUID_t uuid;
size_t totalGlobalMem;
size_t sharedMemPerBlock;
int regsPerBlock;
int warpSize;
size_t memPitch;
int maxThreadsPerBlock;
int maxThreadsDim[3];
int maxGridSize[3];
int clockRate;
size_t totalConstMem;
int major;
int minor;
size_t textureAlignment;
size_t texturePitchAlignment;
int deviceOverlap;
int multiProcessorCount;
int kernelExecTimeoutEnabled;
int integrated;
int canMapHostMemory;
int computeMode;
int maxTexture1D;
int maxTexture1DMipmap;
int maxTexture1DLinear;
int maxTexture2D[2];
int maxTexture2DMipmap[2];
int maxTexture2DLinear[3];
int maxTexture2DGather[2];
int maxTexture3D[3];
int maxTexture3DAlt[3];
int maxTextureCubemap;
int maxTexture1DLayered[2];
int maxTexture2DLayered[3];
int maxTextureCubemapLayered[2];
int maxSurface1D;
int maxSurface2D[2];
int maxSurface3D[3];
int maxSurface1DLayered[2];
int maxSurface2DLayered[3];
int maxSurfaceCubemap;
int maxSurfaceCubemapLayered[2];
size_t surfaceAlignment;
int concurrentKernels;
int ECCEnabled;
int pciBusID;
int pciDeviceID;
int pciDomainID;
int tccDriver;
int asyncEngineCount;
int unifiedAddressing;
int memoryClockRate;
int memoryBusWidth;
int l2CacheSize;
int persistingL2CacheMaxSize;
int maxThreadsPerMultiProcessor;
int streamPrioritiesSupported;
int globalL1CacheSupported;
int localL1CacheSupported;
size_t sharedMemPerMultiprocessor;
int regsPerMultiprocessor;
int managedMemory;
int isMultiGpuBoard;
int multiGpuBoardGroupID;
int singleToDoublePrecisionPerfRatio;
int pageableMemoryAccess;
int concurrentManagedAccess;
int computePreemptionSupported;
int canUseHostPointerForRegisteredMem;
int cooperativeLaunch;
int cooperativeMultiDeviceLaunch;
int pageableMemoryAccessUsesHostPageTables;
int directManagedMemAccessFromHost;
int accessPolicyMaxWindowSize;
};
- where: name[256] is an ASCII string identifying the device. uuid is a 16-byte unique identifier. totalGlobalMem is the total amount of global memory available on the device in bytes. sharedMemPerBlock is the maximum amount of shared memory available to a thread block in bytes. regsPerBlock is the maximum number of 32-bit registers available to a thread block. warpSize is the warp size in threads. memPitch is the maximum pitch in bytes allowed by the memory copy functions that involve memory regions allocated through musaMallocPitch(). maxThreadsPerBlock is the maximum number of threads per block. maxThreadsDim[3] contains the maximum size of each dimension of a block. maxGridSize[3] contains the maximum size of each dimension of a grid. clockRate is the clock frequency in kilohertz. totalConstMem is the total amount of constant memory available on the device in bytes. major, minor are the major and minor revision numbers defining the device's compute capability. textureAlignment is the alignment requirement; texture base addresses that are aligned to textureAlignment bytes do not need an offset applied to texture fetches. texturePitchAlignment is the pitch alignment requirement for 2D texture references that are bound to pitched memory. deviceOverlap is 1 if the device can concurrently copy memory between host and device while executing a kernel, or 0 if not. Deprecated, use instead asyncEngineCount. multiProcessorCount is the number of multiprocessors on the device. kernelExecTimeoutEnabled is 1 if there is a run time limit for kernels executed on the device, or 0 if not. integrated is 1 if the device is an integrated (motherboard) GPU and 0 if it is a discrete (card) component. canMapHostMemory is 1 if the device can map host memory into the MUSA address space for use with musaHostAlloc()/musaHostGetDevicePointer(), or 0 if not. computeMode is the compute mode that the device is currently in. Available modes are as follows: musaComputeModeDefault: Default mode - Device is not restricted and multiple threads can use musaSetDevice() with this device. musaComputeModeProhibited: Compute-prohibited mode - No threads can use musaSetDevice() with this device. musaComputeModeExclusiveProcess: Compute-exclusive-process mode - Many threads in one process will be able to use musaSetDevice() with this device. When an occupied exclusive mode device is chosen with musaSetDevice, all subsequent non-device management runtime functions will return musaErrorDevicesUnavailable. maxTexture1D is the maximum 1D texture size. maxTexture1DMipmap is the maximum 1D mipmapped texture texture size. maxTexture1DLinear is the maximum 1D texture size for textures bound to linear memory. maxTexture2D[2] contains the maximum 2D texture dimensions. maxTexture2DMipmap[2] contains the maximum 2D mipmapped texture dimensions. maxTexture2DLinear[3] contains the maximum 2D texture dimensions for 2D textures bound to pitch linear memory. maxTexture2DGather[2] contains the maximum 2D texture dimensions if texture gather operations have to be performed. maxTexture3D[3] contains the maximum 3D texture dimensions. maxTexture3DAlt[3] contains the maximum alternate 3D texture dimensions. maxTextureCubemap is the maximum cubemap texture width or height. maxTexture1DLayered[2] contains the maximum 1D layered texture dimensions. maxTexture2DLayered[3] contains the maximum 2D layered texture dimensions. maxTextureCubemapLayered[2] contains the maximum cubemap layered texture dimensions. maxSurface1D is the maximum 1D surface size. maxSurface2D[2] contains the maximum 2D surface dimensions. maxSurface3D[3] contains the maximum 3D surface dimensions. maxSurface1DLayered[2] contains the maximum 1D layered surface dimensions. maxSurface2DLayered[3] contains the maximum 2D layered surface dimensions. maxSurfaceCubemap is the maximum cubemap surface width or height. maxSurfaceCubemapLayered[2] contains the maximum cubemap layered surface dimensions. surfaceAlignment specifies the alignment requirements for surfaces. concurrentKernels is 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. ECCEnabled is 1 if the device has ECC support turned on, or 0 if not. pciBusID is the PCI bus identifier of the device. pciDeviceID is the PCI device (sometimes called slot) identifier of the device. pciDomainID is the PCI domain identifier of the device. tccDriver is 1 if the device is using a TCC driver or 0 if not. asyncEngineCount is 1 when the device can concurrently copy memory between host and device while executing a kernel. It is 2 when the device can concurrently copy memory between host and device in both directions and execute a kernel at the same time. It is 0 if neither of these is supported. unifiedAddressing is 1 if the device shares a unified address space with the host and 0 otherwise. memoryClockRate is the peak memory clock frequency in kilohertz. memoryBusWidth is the memory bus width in bits. l2CacheSize is L2 cache size in bytes. persistingL2CacheMaxSize is L2 cache's maximum persisting lines size in bytes. maxThreadsPerMultiProcessor is the number of maximum resident threads per multiprocessor. streamPrioritiesSupported is 1 if the device supports stream priorities, or 0 if it is not supported. globalL1CacheSupported is 1 if the device supports caching of globals in L1 cache, or 0 if it is not supported. localL1CacheSupported is 1 if the device supports caching of locals in L1 cache, or 0 if it is not supported. sharedMemPerMultiprocessor is the maximum amount of shared memory available to a multiprocessor in bytes; this amount is shared by all thread blocks simultaneously resident on a multiprocessor. regsPerMultiprocessor is the maximum number of 32-bit registers available to a multiprocessor; this number is shared by all thread blocks simultaneously resident on a multiprocessor. managedMemory is 1 if the device supports allocating managed memory on this system, or 0 if it is not supported. isMultiGpuBoard is 1 if the device is on a multi-GPU board (e.g. Gemini cards), and 0 if not; multiGpuBoardGroupID is a unique identifier for a group of devices associated with the same board. Devices on the same multi-GPU board will share the same identifier. hostNativeAtomicSupported is 1 if the link between the device and the host supports native atomic operations, or 0 if it is not supported. singleToDoublePrecisionPerfRatio is the ratio of single precision performance (in floating-point operations per second) to double precision performance. pageableMemoryAccess is 1 if the device supports coherently accessing pageable memory without calling musaHostRegister on it, and 0 otherwise. concurrentManagedAccess is 1 if the device can coherently access managed memory concurrently with the CPU, and 0 otherwise. computePreemptionSupported is 1 if the device supports Compute Preemption, and 0 otherwise. canUseHostPointerForRegisteredMem is 1 if the device can access host registered memory at the same virtual address as the CPU, and 0 otherwise. cooperativeLaunch is 1 if the device supports launching cooperative kernels via musaLaunchCooperativeKernel, and 0 otherwise. cooperativeMultiDeviceLaunch is 1 if the device supports launching cooperative kernels via musaLaunchCooperativeKernelMultiDevice, and 0 otherwise. sharedMemPerBlockOptin is the per device maximum shared memory per block usable by special opt in pageableMemoryAccessUsesHostPageTables is 1 if the device accesses pageable memory via the host's page tables, and 0 otherwise. directManagedMemAccessFromHost is 1 if the host can directly access managed memory on the device without migration, and 0 otherwise. maxBlocksPerMultiProcessor is the maximum number of thread blocks that can reside on a multiprocessor. accessPolicyMaxWindowSize is the maximum value of musaAccessPolicyWindow::num_bytes. reservedSharedMemPerBlock is the shared memory reserved by MUSA driver per block in bytes hostRegisterSupported is 1 if the device supports host memory registration via musaHostRegister, and 0 otherwise. sparseMusaArraySupported is 1 if the device supports sparse MUSA arrays and sparse MUSA mipmapped arrays, 0 otherwise hostRegisterReadOnlySupported is 1 if the device supports using the musaHostRegister flag musaHostRegisterReadOnly to register memory that must be mapped as read-only to the GPU timelineSemaphoreInteropSupported is 1 if external timeline semaphore interop is supported on the device, 0 otherwise memoryPoolsSupported is 1 if the device supports using the musaMallocAsync and musaMemPool family of APIs, 0 otherwise gpuDirectRDMASupported is 1 if the device supports GPUDirect RDMA APIs, 0 otherwise gpuDirectRDMAFlushWritesOptions is a bitmask to be interpreted according to the musaFlushGPUDirectRDMAWritesOptions enum gpuDirectRDMAWritesOrdering See the musaGPUDirectRDMAWritesOrdering enum for numerical values memoryPoolSupportedHandleTypes is a bitmask of handle types supported with mempool-based IPC deferredMappingMusaArraySupported is 1 if the device supports deferred mapping MUSA arrays and MUSA mipmapped arrays ipcEventSupported is 1 if the device supports IPC Events, and 0 otherwise unifiedFunctionPointers is 1 if the device support unified pointers, and 0 otherwise prop - Properties for the specified device device - Device number to get properties for musaSuccess, musaErrorInvalidDevice This function may also return error codes from previous, asynchronous launches. This call may initialize internal runtime state and may also return initialization-related errors. No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic. musaGetDeviceCount, musaGetDevice, musaSetDevice, musaChooseDevice, musaDeviceGetAttribute, musaInitDevice, muDeviceGetAttribute, muDeviceGetName
Parameters
prop(struct musaDeviceProp *): Properties for the specified devicedevice(int): Device number to get properties for
Returns
- musaSuccess, musaErrorInvalidDevice
Note
- Additional exported symbol names in scope:
musaGetDeviceProperties_v2. - This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
See also
- musaGetDeviceCount, musaGetDevice, musaSetDevice, musaChooseDevice, musaDeviceGetAttribute, musaInitDevice, muDeviceGetAttribute, muDeviceGetName
musaDeviceGetAttribute
musaError_t musaDeviceGetAttribute(int *value, enum musaDeviceAttr attr, int device)
Description
- Returns information about the device.
- Returns in *value the integer value of the attribute attr on device device. The supported attributes are: musaDevAttrMaxThreadsPerBlock: Maximum number of threads per block musaDevAttrMaxBlockDimX: Maximum x-dimension of a block musaDevAttrMaxBlockDimY: Maximum y-dimension of a block musaDevAttrMaxBlockDimZ: Maximum z-dimension of a block musaDevAttrMaxGridDimX: Maximum x-dimension of a grid musaDevAttrMaxGridDimY: Maximum y-dimension of a grid musaDevAttrMaxGridDimZ: Maximum z-dimension of a grid musaDevAttrMaxSharedMemoryPerBlock: Maximum amount of shared memory available to a thread block in bytes musaDevAttrTotalConstantMemory: Memory available on device for constant variables in a MUSA C kernel in bytes musaDevAttrWarpSize: Warp size in threads musaDevAttrMaxPitch: Maximum pitch in bytes allowed by the memory copy functions that involve memory regions allocated through musaMallocPitch() musaDevAttrMaxTexture1DWidth: Maximum 1D texture width musaDevAttrMaxTexture1DLinearWidth: Maximum width for a 1D texture bound to linear memory musaDevAttrMaxTexture1DMipmappedWidth: Maximum mipmapped 1D texture width musaDevAttrMaxTexture2DWidth: Maximum 2D texture width musaDevAttrMaxTexture2DHeight: Maximum 2D texture height musaDevAttrMaxTexture2DLinearWidth: Maximum width for a 2D texture bound to linear memory musaDevAttrMaxTexture2DLinearHeight: Maximum height for a 2D texture bound to linear memory musaDevAttrMaxTexture2DLinearPitch: Maximum pitch in bytes for a 2D texture bound to linear memory musaDevAttrMaxTexture2DMipmappedWidth: Maximum mipmapped 2D texture width musaDevAttrMaxTexture2DMipmappedHeight: Maximum mipmapped 2D texture height musaDevAttrMaxTexture3DWidth: Maximum 3D texture width musaDevAttrMaxTexture3DHeight: Maximum 3D texture height musaDevAttrMaxTexture3DDepth: Maximum 3D texture depth musaDevAttrMaxTexture3DWidthAlt: Alternate maximum 3D texture width, 0 if no alternate maximum 3D texture size is supported musaDevAttrMaxTexture3DHeightAlt: Alternate maximum 3D texture height, 0 if no alternate maximum 3D texture size is supported musaDevAttrMaxTexture3DDepthAlt: Alternate maximum 3D texture depth, 0 if no alternate maximum 3D texture size is supported musaDevAttrMaxTextureCubemapWidth: Maximum cubemap texture width or height musaDevAttrMaxTexture1DLayeredWidth: Maximum 1D layered texture width musaDevAttrMaxTexture1DLayeredLayers: Maximum layers in a 1D layered texture musaDevAttrMaxTexture2DLayeredWidth: Maximum 2D layered texture width musaDevAttrMaxTexture2DLayeredHeight: Maximum 2D layered texture height musaDevAttrMaxTexture2DLayeredLayers: Maximum layers in a 2D layered texture musaDevAttrMaxTextureCubemapLayeredWidth: Maximum cubemap layered texture width or height musaDevAttrMaxTextureCubemapLayeredLayers: Maximum layers in a cubemap layered texture musaDevAttrMaxSurface1DWidth: Maximum 1D surface width musaDevAttrMaxSurface2DWidth: Maximum 2D surface width musaDevAttrMaxSurface2DHeight: Maximum 2D surface height musaDevAttrMaxSurface3DWidth: Maximum 3D surface width musaDevAttrMaxSurface3DHeight: Maximum 3D surface height musaDevAttrMaxSurface3DDepth: Maximum 3D surface depth musaDevAttrMaxSurface1DLayeredWidth: Maximum 1D layered surface width musaDevAttrMaxSurface1DLayeredLayers: Maximum layers in a 1D layered surface musaDevAttrMaxSurface2DLayeredWidth: Maximum 2D layered surface width musaDevAttrMaxSurface2DLayeredHeight: Maximum 2D layered surface height musaDevAttrMaxSurface2DLayeredLayers: Maximum layers in a 2D layered surface musaDevAttrMaxSurfaceCubemapWidth: Maximum cubemap surface width musaDevAttrMaxSurfaceCubemapLayeredWidth: Maximum cubemap layered surface width musaDevAttrMaxSurfaceCubemapLayeredLayers: Maximum layers in a cubemap layered surface musaDevAttrMaxRegistersPerBlock: Maximum number of 32-bit registers available to a thread block musaDevAttrClockRate: Peak clock frequency in kilohertz musaDevAttrTextureAlignment: Alignment requirement; texture base addresses aligned to textureAlign bytes do not need an offset applied to texture fetches musaDevAttrTexturePitchAlignment: Pitch alignment requirement for 2D texture references bound to pitched memory musaDevAttrGpuOverlap: 1 if the device can concurrently copy memory between host and device while executing a kernel, or 0 if not musaDevAttrMultiProcessorCount: Number of multiprocessors on the device musaDevAttrKernelExecTimeout: 1 if there is a run time limit for kernels executed on the device, or 0 if not musaDevAttrIntegrated: 1 if the device is integrated with the memory subsystem, or 0 if not musaDevAttrCanMapHostMemory: 1 if the device can map host memory into the MUSA address space, or 0 if not musaDevAttrComputeMode: Compute mode is the compute mode that the device is currently in. Available modes are as follows: musaComputeModeDefault: Default mode - Device is not restricted and multiple threads can use musaSetDevice() with this device. musaComputeModeProhibited: Compute-prohibited mode - No threads can use musaSetDevice() with this device. musaComputeModeExclusiveProcess: Compute-exclusive-process mode - Many threads in one process will be able to use musaSetDevice() with this device. musaDevAttrConcurrentKernels: 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. musaDevAttrEccEnabled: 1 if error correction is enabled on the device, 0 if error correction is disabled or not supported by the device musaDevAttrPciBusId: PCI bus identifier of the device musaDevAttrPciDeviceId: PCI device (also known as slot) identifier of the device musaDevAttrTccDriver: 1 if the device is using a TCC driver. TCC is only available on Tesla hardware running Windows Vista or later. musaDevAttrMemoryClockRate: Peak memory clock frequency in kilohertz musaDevAttrGlobalMemoryBusWidth: Global memory bus width in bits musaDevAttrL2CacheSize: Size of L2 cache in bytes. 0 if the device doesn't have L2 cache. musaDevAttrMaxThreadsPerMultiProcessor: Maximum resident threads per multiprocessor musaDevAttrUnifiedAddressing: 1 if the device shares a unified address space with the host, or 0 if not musaDevAttrComputeCapabilityMajor: Major compute capability version number musaDevAttrComputeCapabilityMinor: Minor compute capability version number musaDevAttrStreamPrioritiesSupported: 1 if the device supports stream priorities, or 0 if not musaDevAttrGlobalL1CacheSupported: 1 if device supports caching globals in L1 cache, 0 if not musaDevAttrLocalL1CacheSupported: 1 if device supports caching locals in L1 cache, 0 if not musaDevAttrMaxSharedMemoryPerMultiprocessor: Maximum amount of shared memory available to a multiprocessor in bytes; this amount is shared by all thread blocks simultaneously resident on a multiprocessor musaDevAttrMaxRegistersPerMultiprocessor: Maximum number of 32-bit registers available to a multiprocessor; this number is shared by all thread blocks simultaneously resident on a multiprocessor musaDevAttrManagedMemory: 1 if device supports allocating managed memory, 0 if not musaDevAttrIsMultiGpuBoard: 1 if device is on a multi-GPU board, 0 if not musaDevAttrMultiGpuBoardGroupID: Unique identifier for a group of devices on the same multi-GPU board musaDevAttrHostNativeAtomicSupported: 1 if the link between the device and the host supports native atomic operations musaDevAttrSingleToDoublePrecisionPerfRatio: Ratio of single precision performance (in floating-point operations per second) to double precision performance musaDevAttrPageableMemoryAccess: 1 if the device supports coherently accessing pageable memory without calling musaHostRegister on it, and 0 otherwise musaDevAttrConcurrentManagedAccess: 1 if the device can coherently access managed memory concurrently with the CPU, and 0 otherwise musaDevAttrComputePreemptionSupported: 1 if the device supports Compute Preemption, 0 if not musaDevAttrCanUseHostPointerForRegisteredMem: 1 if the device can access host registered memory at the same virtual address as the CPU, and 0 otherwise musaDevAttrCooperativeLaunch: 1 if the device supports launching cooperative kernels via musaLaunchCooperativeKernel, and 0 otherwise musaDevAttrCooperativeMultiDeviceLaunch: 1 if the device supports launching cooperative kernels via musaLaunchCooperativeKernelMultiDevice, and 0 otherwise musaDevAttrCanFlushRemoteWrites: 1 if the device supports flushing of outstanding remote writes, and 0 otherwise musaDevAttrHostRegisterSupported: 1 if the device supports host memory registration via musaHostRegister, and 0 otherwise musaDevAttrPageableMemoryAccessUsesHostPageTables: 1 if the device accesses pageable memory via the host's page tables, and 0 otherwise musaDevAttrDirectManagedMemAccessFromHost: 1 if the host can directly access managed memory on the device without migration, and 0 otherwise musaDevAttrMaxSharedMemoryPerBlockOptin: Maximum per block shared memory size on the device. This value can be opted into when using musaFuncSetAttribute musaDevAttrMaxBlocksPerMultiprocessor: Maximum number of thread blocks that can reside on a multiprocessor musaDevAttrMaxPersistingL2CacheSize: Maximum L2 persisting lines capacity setting in bytes musaDevAttrMaxAccessPolicyWindowSize: Maximum value of musaAccessPolicyWindow::num_bytes musaDevAttrReservedSharedMemoryPerBlock: Shared memory reserved by MUSA driver per block in bytes musaDevAttrSparseMusaArraySupported: 1 if the device supports sparse MUSA arrays and sparse MUSA mipmapped arrays. musaDevAttrHostRegisterReadOnlySupported: Device supports using the musaHostRegister flag musaHostRegisterReadOnly to register memory that must be mapped as read-only to the GPU musaDevAttrMemoryPoolsSupported: 1 if the device supports using the musaMallocAsync and musaMemPool family of APIs, and 0 otherwise musaDevAttrGPUDirectRDMASupported: 1 if the device supports GPUDirect RDMA APIs, and 0 otherwise musaDevAttrGPUDirectRDMAFlushWritesOptions: bitmask to be interpreted according to the musaFlushGPUDirectRDMAWritesOptions enum musaDevAttrGPUDirectRDMAWritesOrdering: see the musaGPUDirectRDMAWritesOrdering enum for numerical values musaDevAttrMemoryPoolSupportedHandleTypes: Bitmask of handle types supported with mempool based IPC musaDevAttrDeferredMappingMusaArraySupported : 1 if the device supports deferred mapping MUSA arrays and MUSA mipmapped arrays. musaDevAttrIpcEventSupport: 1 if the device supports IPC Events. musaDevAttrNumaConfig: NUMA configuration of a device: value is of type musaDeviceNumaConfig enum musaDevAttrNumaId: NUMA node ID of the GPU memory musaDevAttrGpuPciDeviceId: The combined 16-bit PCI device ID and 16-bit PCI vendor ID. musaDevAttrGpuPciSubsystemId: The combined 16-bit PCI subsystem ID and 16-bit PCI vendor subsystem ID.
Parameters
value(int *): Returned device attribute valueattr(enum musaDeviceAttr): Device attribute to querydevice(int): Device number to query
Returns
- musaSuccess, musaErrorInvalidDevice, musaErrorInvalidValue
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
See also
- musaGetDeviceCount, musaGetDevice, musaSetDevice, musaChooseDevice, musaGetDeviceProperties, musaInitDevice, muDeviceGetAttribute
musaDeviceGetDefaultMemPool
musaError_t musaDeviceGetDefaultMemPool(musaMemPool_t *memPool, int device)
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 musaAtomicOperation in *operations, the corresponding result in *capabilities will be a bitmask indicating which of musaAtomicOperationCapability the link supports natively.
- Returns musaErrorInvalidDevice if dev is not valid.
- Returns musaErrorInvalidValue if *capabilities or *operations is NULL, if count is 0, or if any of *operations is not valid.
- The default mempool of a device contains device memory from that device.
Parameters
memPool(musaMemPool_t *)device(int)
Returns
- musaSuccess, musaErrorInvalidDevice, musaErrorInvalidValue
- musaSuccess, musaErrorInvalidDevice, musaErrorInvalidValue musaErrorNotSupported
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
See also
- musaDeviceGetAttribute, musaDeviceGetP2PAtomicCapabilities, muDeviceGeHostAtomicCapabilities
- muDeviceGetDefaultMemPool, musaMallocAsync, musaMemPoolTrimTo, musaMemPoolGetAttribute, musaDeviceSetMemPool, musaMemPoolSetAttribute, musaMemPoolSetAccess
musaDeviceSetMemPool
musaError_t musaDeviceSetMemPool(int device, musaMemPool_t memPool)
Description
- Sets the current memory pool of a device.
- The memory pool must be local to the specified device. Unless a mempool is specified in the musaMallocAsync call, musaMallocAsync 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
device(int)memPool(musaMemPool_t)
Returns
- musaSuccess, musaErrorInvalidValue musaErrorInvalidDevice musaErrorNotSupported
Note
- Use musaMallocFromPoolAsync to specify asynchronous allocations from a device different than the one the stream runs on.
- This function may also return error codes from previous, asynchronous launches.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
See also
- muDeviceSetMemPool, musaDeviceGetMemPool, musaDeviceGetDefaultMemPool, musaMemPoolCreate, musaMemPoolDestroy, musaMallocFromPoolAsync
musaDeviceGetMemPool
musaError_t musaDeviceGetMemPool(musaMemPool_t *memPool, int device)
Description
- Gets the current mempool for a device.
- Returns the last pool provided to musaDeviceSetMemPool for this device or the device's default memory pool if musaDeviceSetMemPool 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 or musaDeviceSetMemPool.
Parameters
memPool(musaMemPool_t *)device(int)
Returns
- musaSuccess, musaErrorInvalidValue musaErrorNotSupported
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
See also
musaMemGetDefaultMemPool
musaError_t musaMemGetDefaultMemPool(musaMemPool_t *memPool, struct musaMemLocation *location, enum musaMemAllocationType type)
Description
- Returns the default memory pool for a given location and allocation type.
- The memory location can be of one of musaMemLocationTypeDevice, musaMemLocationTypeHost or musaMemLocationTypeHostNuma. The allocation type can be one of musaMemAllocationTypePinned or musaMemAllocationTypeManaged. When the allocation type is musaMemAllocationTypeManaged, the location type can also be musaMemLocationTypeNone to indicate no preferred location for the managed memory pool. In all other cases, the call returns musaErrorInvalidValue.
Parameters
memPool(musaMemPool_t *): Returned default memory poollocation(struct musaMemLocation *): Memory location identifying the pooltype(enum musaMemAllocationType): Allocation type identifying the pool
Returns
- musaSuccess, musaErrorInvalidValue, musaErrorNotSupported
Note
- Experimental in the current MUSA SDK 5.2.0 delivery scope.
- This function may also return error codes from previous, asynchronous launches.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
See also
- muMemAllocAsync, muMemPoolTrimTo, muMemPoolGetAttribute, muMemPoolSetAttribute, muMemPoolSetAccess, musaMemGetMemPool, musaMemPoolCreate
musaMemGetMemPool
musaError_t musaMemGetMemPool(musaMemPool_t *memPool, struct musaMemLocation *location, enum musaMemAllocationType type)
Description
- Gets the current memory pool for a given memory location and allocation type.
- The memory location can be of one of musaMemLocationTypeDevice, musaMemLocationTypeHost or musaMemLocationTypeHostNuma. The allocation type can be one of musaMemAllocationTypePinned or musaMemAllocationTypeManaged. When the allocation type is musaMemAllocationTypeManaged, the location type can also be musaMemLocationTypeNone to indicate no preferred location for the managed memory pool. In all other cases, the call returns musaErrorInvalidValue.
- Returns the last pool provided to musaMemSetMemPool or musaDeviceSetMemPool for this location and allocation type, or the location's default memory pool if musaMemSetMemPool or musaDeviceSetMemPool for that allocType and location has never been called. By default the current mempool of a location is the default mempool for a device that can be obtained via musaMemGetDefaultMemPool. Otherwise the returned pool must have been set with musaDeviceSetMemPool.
Parameters
memPool(musaMemPool_t *): Returned current memory poollocation(struct musaMemLocation *): Memory location identifying the pooltype(enum musaMemAllocationType): Allocation type identifying the pool
Returns
- musaSuccess, musaErrorInvalidValue
Note
- Experimental in the current MUSA SDK 5.2.0 delivery scope.
- This function may also return error codes from previous, asynchronous launches.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
See also
musaMemSetMemPool
musaError_t musaMemSetMemPool(struct musaMemLocation *location, enum musaMemAllocationType type, musaMemPool_t memPool)
Description
- Sets the current memory pool for a memory location and allocation type.
- The memory location can be of one of musaMemLocationTypeDevice, musaMemLocationTypeHost or musaMemLocationTypeHostNuma. The allocation type can be one of musaMemAllocationTypePinned or musaMemAllocationTypeManaged. When the allocation type is musaMemAllocationTypeManaged, the location type can also be musaMemLocationTypeNone to indicate no preferred location for the managed memory pool. In all other cases, the call returns musaErrorInvalidValue.
- When a memory pool is set as the current memory pool, the location parameter should be the same as the location of the pool. If the location type or index do not match, the call returns musaErrorInvalidValue. The type of memory pool should also match the parameter type, else the call returns musaErrorInvalidValue. By default, a memory location's current memory pool is its default memory pool. If the location type is musaMemLocationTypeDevice and the allocation type is musaMemAllocationTypePinned, then this API is the equivalent of calling musaDeviceSetMemPool with the location id as the device.
Parameters
location(struct musaMemLocation *): Memory location for which to set the pooltype(enum musaMemAllocationType): Allocation type for which to set the poolmemPool(musaMemPool_t): Memory pool to set as current
Returns
- musaSuccess, musaErrorInvalidValue
Note
- Experimental in the current MUSA SDK 5.2.0 delivery scope.
- Use musaMallocFromPoolAsync to specify asynchronous allocations from a device different than the one the stream runs on.
- This function may also return error codes from previous, asynchronous launches.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
See also
- muDeviceGetDefaultMemPool, muDeviceGetMemPool, musaMemGetMemPool, musaMemPoolCreate, musaMemPoolDestroy, musaMallocFromPoolAsync
musaDeviceGetP2PAttribute
musaError_t musaDeviceGetP2PAttribute(int *value, enum musaDeviceP2PAttr attr, int srcDevice, int dstDevice)
Description
- Return MtSciSync attributes that this device can support.
- Returns in mtSciSyncAttrList, the properties of MtSciSync that this MUSA device, dev can support. The returned mtSciSyncAttrList can be used to create an MtSciSync that matches this device's capabilities.
- If MtSciSyncAttrKey_RequiredPerm field in mtSciSyncAttrList is already set this API will return musaErrorInvalidValue.
- The applications should set mtSciSyncAttrList to a valid MtSciSyncAttrList failing which this API will return musaErrorInvalidHandle.
- The flags controls how applications intends to use the MtSciSync created from the mtSciSyncAttrList. The valid flags are: musaMtSciSyncAttrSignal, specifies that the applications intends to signal an MtSciSync on this MUSA device. musaMtSciSyncAttrWait, specifies that the applications intends to wait on an MtSciSync on this MUSA device.
- At least one of these flags must be set, failing which the API returns musaErrorInvalidValue. 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: MtSciSyncAttrKey_RequiredPerm is set to MtSciSyncAccessPerm_SignalOnly if musaMtSciSyncAttrSignal is set in flags. MtSciSyncAccessPerm_WaitOnly if musaMtSciSyncAttrWait is set in flags. MtSciSyncAccessPerm_WaitSignal if both musaMtSciSyncAttrWait and musaMtSciSyncAttrSignal are set in flags. MtSciSyncAttrKey_PrimitiveInfo is set to MtSciSyncAttrValPrimitiveType_SysmemSemaphore on any valid device. MtSciSyncAttrValPrimitiveType_Syncpoint if device is a Tegra device. MtSciSyncAttrValPrimitiveType_SysmemSemaphorePayload64b if device is GA10X+. MtSciSyncAttrKey_GpuId is set to the same UUID that is returned in musaDeviceProp.uuid from musaDeviceGetProperties for this device.
- Returns in *value the value of the requested attribute attrib of the link between srcDevice and dstDevice. The supported attributes are: musaDevP2PAttrPerformanceRank: A relative value indicating the performance of the link between two devices. Lower value means better performance (0 being the value used for most performant link). musaDevP2PAttrAccessSupported: 1 if peer access is enabled. musaDevP2PAttrNativeAtomicSupported: 1 if native atomic operations over the link are supported. musaDevP2PAttrMusaArrayAccessSupported: 1 if accessing MUSA arrays over the link is supported. musaDevP2PAttrOnlyPartialNativeAtomicSupported: 1 if some MUSA-valid atomic operations over the link are supported. Information about specific operations can be retrieved with musaDeviceGetP2PAtomicCapabilities.
- Returns musaErrorInvalidDevice if srcDevice or dstDevice are not valid or if they represent the same device.
- Returns musaErrorInvalidValue if attrib is not valid or if value is a null pointer.
Parameters
value(int *): Returned value of the requested attributeattr(enum musaDeviceP2PAttr)srcDevice(int): The source device of the target link.dstDevice(int): The destination device of the target link.
Returns
- musaSuccess, musaErrorInvalidDevice, musaErrorInvalidValue
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
See also
- musaImportExternalSemaphore, musaDestroyExternalSemaphore, musaSignalExternalSemaphoresAsync, musaWaitExternalSemaphoresAsync
- musaDeviceEnablePeerAccess, musaDeviceDisablePeerAccess, musaDeviceCanAccessPeer, muDeviceGetP2PAttribute
musaChooseDevice
musaError_t musaChooseDevice(int *device, const struct musaDeviceProp *prop)
Description
- Queries details about atomic operations supported between two devices.
- Returns in *capabilities the details about requested atomic *operations over the the link between srcDevice and dstDevice. The allocated size of *operations and *capabilities must be count.
- For each musaAtomicOperation in *operations, the corresponding result in *capabilities will be a bitmask indicating which of musaAtomicOperationCapability the link supports natively.
- Returns musaErrorInvalidDevice if srcDevice or dstDevice are not valid or if they represent the same device.
- Returns musaErrorInvalidValue if *capabilities or *operations is NULL, if count is 0, or if any of *operations is not valid.
- Returns in *device the device which has properties that best match *prop.
Parameters
device(int *): Device with best matchprop(const struct musaDeviceProp *): Desired device properties
Returns
- musaSuccess, musaErrorInvalidDevice, musaErrorInvalidValue
- musaSuccess, musaErrorInvalidValue
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
See also
- musaDeviceGetP2PAttribute, muDeviceGetP2PAttribute, muDeviceGetP2PAtomicCapabilities
- musaGetDeviceCount, musaGetDevice, musaSetDevice, musaGetDeviceProperties, musaInitDevice
musaInitDevice
musaError_t musaInitDevice(int device, unsigned int deviceFlags, unsigned int flags)
Description
- Initialize device to be used for GPU executions.
- This function will initialize the MUSA Runtime structures and primary context on device when called, but the context will not be made current to device.
- When musaInitDeviceFlagsAreValid is set in flags, deviceFlags are applied to the requested device. The values of deviceFlags match those of the flags parameters in musaSetDeviceFlags. The effect may be verified by musaGetDeviceFlags.
- This function will return an error if the device is in musaComputeModeExclusiveProcess and is occupied by another process or if the device is in musaComputeModeProhibited.
Parameters
device(int): Device on which the runtime will initialize itself.deviceFlags(unsigned int): Parameters for device operation.flags(unsigned int): Flags for controlling the device initialization.
Returns
- musaSuccess, musaErrorInvalidDevice
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
See also
- musaGetDeviceCount, musaGetDevice, musaGetDeviceProperties, musaChooseDevice, musaSetDevice muCtxSetCurrent
musaSetDevice
musaError_t musaSetDevice(int device)
Description
- Set device to be used for GPU executions.
- Sets device as the current device for the calling host thread. Valid device id's are 0 to (musaGetDeviceCount() - 1).
- Any device memory subsequently allocated from this host thread using musaMalloc(), musaMallocPitch() or musaMallocArray() will be physically resident on device. Any host memory allocated from this host thread using musaMallocHost() or musaHostAlloc() or musaHostRegister() will have its lifetime associated with device. Any streams or events created from this host thread will be associated with device. Any kernels launched from this host thread using the
<<<>>>operator or musaLaunchKernel() will be executed on device. - This call may be made from any host thread, to any device, and at any time. This function will do no synchronization with the previous or new device, and should only take significant time when it initializes the runtime's context state. This call will bind the primary context of the specified device to the calling thread and all the subsequent memory allocations, stream and event creations, and kernel launches will be associated with the primary context. This function will also immediately initialize the runtime state on the primary context, and the context will be current on device immediately. This function will return an error if the device is in musaComputeModeExclusiveProcess and is occupied by another process or if the device is in musaComputeModeProhibited.
Parameters
device(int): Device on which the active host thread should execute the device code.
Returns
- musaSuccess, musaErrorInvalidDevice, musaErrorDeviceUnavailable
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
See also
- musaGetDeviceCount, musaGetDevice, musaGetDeviceProperties, musaChooseDevice, musaInitDevice, muCtxSetCurrent
musaGetDevice
musaError_t musaGetDevice(int *device)
Description
- Returns which device is currently being used.
- Returns in *device the current device for the calling host thread.
Parameters
device(int *): Returns the device on which the active host thread executes the device code.
Returns
- musaSuccess, musaErrorInvalidValue, musaErrorDeviceUnavailable
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
See also
musaSetDeviceFlags
musaError_t musaSetDeviceFlags(unsigned int flags)
Description
- Set a list of devices that can be used for MUSA.
- Sets a list of devices for MUSA execution in priority order using device_arr. The parameter len specifies the number of elements in the list. MUSA will try devices from the list sequentially until it finds one that works. If this function is not called, or if it is called with a len of 0, then MUSA will go back to its default behavior of trying devices sequentially from a default list containing all of the available MUSA devices in the system. If a specified device ID in the list does not exist, this function will return musaErrorInvalidDevice. If len is not 0 and device_arr is NULL or if len exceeds the number of devices in the system, then musaErrorInvalidValue is returned.
- Records flags as the flags for the current device. If the current device has been set and that device has already been initialized, the previous flags are overwritten. If the current device has not been initialized, it is initialized with the provided flags. If no device has been made current to the calling thread, a default device is selected and initialized with the provided flags.
- The three LSBs of the flags parameter can be used to control how the CPU thread interacts with the OS scheduler when waiting for results from the device.
- musaDeviceScheduleAuto: 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 device, otherwise MUSA will not yield while waiting for results and actively spin on the processor. Additionally, on Tegra devices, musaDeviceScheduleAuto uses a heuristic based on the power profile of the platform and may choose musaDeviceScheduleBlockingSync for low-powered devices. musaDeviceScheduleSpin: Instruct MUSA to actively spin when waiting for results from the device. This can decrease latency when waiting for the device, but may lower the performance of CPU threads if they are performing work in parallel with the MUSA thread. musaDeviceScheduleYield: Instruct MUSA to yield its thread when waiting for results from the device. This can increase latency when waiting for the device, but can increase the performance of CPU threads performing work in parallel with the device. musaDeviceScheduleBlockingSync: Instruct MUSA to block the CPU thread on a synchronization primitive when waiting for the device to finish work. musaDeviceBlockingSync: Instruct MUSA to block the CPU thread on a synchronization primitive when waiting for the device to finish work. Deprecated: This flag was deprecated as of MUSA 4.0 and replaced with musaDeviceScheduleBlockingSync. musaDeviceMapHost: This flag enables allocating pinned host memory that is accessible to the device. It is implicit for the runtime but may be absent if a context is created using the driver API. If this flag is not set, musaHostGetDevicePointer() will always return a failure code. musaDeviceLmemResizeToMax: 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. musaDeviceSyncMemops: 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
flags(unsigned int): Parameters for device operation
Returns
- musaSuccess, musaErrorInvalidValue, musaErrorInvalidDevice
- musaSuccess, musaErrorInvalidValue
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
See also
- musaGetDeviceCount, musaSetDevice, musaGetDeviceProperties, musaSetDeviceFlags, musaChooseDevice
- musaGetDeviceFlags, musaGetDeviceCount, musaGetDevice, musaGetDeviceProperties, musaSetDevice, musaSetValidDevices, musaInitDevice, musaChooseDevice, muDevicePrimaryCtxSetFlags
musaGetDeviceFlags
musaError_t musaGetDeviceFlags(unsigned int *flags)
Description
- Gets the flags for the current device.
- Returns in flags the flags for the current device. If there is a current device for the calling thread, the flags for the device are returned. If there is no current device, the flags for the first device are returned, which may be the default flags. Compare to the behavior of musaSetDeviceFlags.
- Typically, the flags returned should match the behavior that will be seen if the calling thread uses a device after this call, without any change to the flags or current device inbetween by this or another thread. Note that if the device is not initialized, it is possible for another thread to change the flags for the current device before it is initialized. Additionally, when using exclusive mode, if this thread has not requested a specific device, it may use a device other than the first device, contrary to the assumption made by this function.
- If a context has been created via the driver API and is current to the calling thread, the flags for that context are always returned.
- Flags returned by this function may specifically include musaDeviceMapHost even though it is not accepted by musaSetDeviceFlags because it is implicit in runtime API flags. The reason for this is that the current context may have been created via the driver API in which case the flag is not implicit and may be unset.
Parameters
flags(unsigned int *): Pointer to store the device flags
Returns
- musaSuccess, musaErrorInvalidDevice
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
See also
- musaGetDevice, musaGetDeviceProperties, musaSetDevice, musaSetDeviceFlags, musaInitDevice, muCtxGetFlags, muDevicePrimaryCtxGetState
3.3 Device Management [DEPRECATED]
musaDeviceGetSharedMemConfig
musaError_t musaDeviceGetSharedMemConfig(enum musaSharedMemConfig *pConfig)
Description
- Returns the shared memory configuration for the current device.
- Deprecated
- This function will return in pConfig the current size of shared memory banks on the current device. On devices with configurable shared memory banks, musaDeviceSetSharedMemConfig can be used to change this setting, so that all subsequent kernel launches will by default use the new bank size. When musaDeviceGetSharedMemConfig 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: musaSharedMemBankSizeFourByte - shared memory bank width is four bytes. musaSharedMemBankSizeEightByte - shared memory bank width is eight bytes.
Parameters
pConfig(enum musaSharedMemConfig *): Returned cache configuration
Returns
- musaSuccess, musaErrorInvalidValue
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
See also
- musaDeviceSetCacheConfig, musaDeviceGetCacheConfig, musaDeviceSetSharedMemConfig, musaFuncSetCacheConfig, muCtxGetSharedMemConfig
musaDeviceSetSharedMemConfig
musaError_t musaDeviceSetSharedMemConfig(enum musaSharedMemConfig config)
Description
- Sets the shared memory configuration for the current device.
- Deprecated
- On devices with configurable shared memory banks, this function will set the shared memory bank size which is used for all subsequent kernel launches. Any per-function setting of shared memory set via musaFuncSetSharedMemConfig will override the device wide setting.
- Changing the shared memory configuration between launches may introduce a device side synchronization point.
- 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: musaSharedMemBankSizeDefault: set bank width the device default (currently, four bytes) musaSharedMemBankSizeFourByte: set shared memory bank width to be four bytes natively. musaSharedMemBankSizeEightByte: set shared memory bank width to be eight bytes natively.
Parameters
config(enum musaSharedMemConfig): Requested cache configuration
Returns
- musaSuccess, musaErrorInvalidValue
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
See also
- musaDeviceSetCacheConfig, musaDeviceGetCacheConfig, musaDeviceGetSharedMemConfig, musaFuncSetCacheConfig, muCtxSetSharedMemConfig
3.4 Thread Management [DEPRECATED]
musaThreadExit
musaError_t musaThreadExit(void)
Description
- Exit and clean up from MUSA launches.
- Deprecated
- Note that this function is deprecated because its name does not reflect its behavior. Its functionality is identical to the non-deprecated function musaDeviceReset(), which should be used instead.
- Explicitly destroys all cleans up all resources associated with the current device in the current process. Any subsequent API call to this device will reinitialize the device.
- Note that this function will reset the device immediately. It is the caller's responsibility to ensure that the device is not being accessed by any other host threads from the process when this function is called.
Parameters
(unnamed)(void)
Returns
- musaSuccess
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
See also
musaThreadSynchronize
musaError_t musaThreadSynchronize(void)
Description
- Wait for compute device to finish.
- Deprecated
- Note that this function is deprecated because its name does not reflect its behavior. Its functionality is similar to the non-deprecated function musaDeviceSynchronize(), which should be used instead.
- Blocks until the device has completed all preceding requested tasks. musaThreadSynchronize() returns an error if one of the preceding tasks has failed. If the musaDeviceScheduleBlockingSync flag was set for this device, the host thread will block until the device has finished its work.
Parameters
(unnamed)(void)
Returns
- musaSuccess
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
See also
musaThreadSetLimit
musaError_t musaThreadSetLimit(enum musaLimit limit, size_t value)
Description
- Set resource limits.
- Deprecated
- Note that this function is deprecated because its name does not reflect its behavior. Its functionality is identical to the non-deprecated function musaDeviceSetLimit(), which should be used instead.
- Setting limit to value is a request by the application to update the current limit maintained by the device. 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 musaThreadGetLimit() to find out exactly what the limit has been set to.
- Setting each musaLimit has its own specific restrictions, so each is discussed here.
- musaLimitStackSize controls the stack size of each GPU thread. musaLimitPrintfFifoSize controls the size of the shared FIFO used by the printf() device system call. Setting musaLimitPrintfFifoSize must be performed before launching any kernel that uses the printf() device system call, otherwise musaErrorInvalidValue will be returned. musaLimitMallocHeapSize controls the size of the heap used by the malloc() and free() device system calls. Setting musaLimitMallocHeapSize must be performed before launching any kernel that uses the malloc() or free() device system calls, otherwise musaErrorInvalidValue will be returned.
Parameters
limit(enum musaLimit): Limit to setvalue(size_t): Size in bytes of limit
Returns
- musaSuccess, musaErrorUnsupportedLimit, musaErrorInvalidValue
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
See also
musaThreadGetLimit
musaError_t musaThreadGetLimit(size_t *pValue, enum musaLimit limit)
Description
- Returns resource limits.
- Deprecated
- Note that this function is deprecated because its name does not reflect its behavior. Its functionality is identical to the non-deprecated function musaDeviceGetLimit(), which should be used instead.
- Returns in *pValue the current size of limit. The supported musaLimit values are: musaLimitStackSize: stack size of each GPU thread; musaLimitPrintfFifoSize: size of the shared FIFO used by the printf() device system call. musaLimitMallocHeapSize: size of the heap used by the malloc() and free() device system calls;
Parameters
pValue(size_t *): Returned size in bytes of limitlimit(enum musaLimit): Limit to query
Returns
- musaSuccess, musaErrorUnsupportedLimit, musaErrorInvalidValue
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
See also
musaThreadGetCacheConfig
musaError_t musaThreadGetCacheConfig(enum musaFuncCache *pCacheConfig)
Description
- Returns the preferred cache configuration for the current device.
- Deprecated
- Note that this function is deprecated because its name does not reflect its behavior. Its functionality is identical to the non-deprecated function musaDeviceGetCacheConfig(), which should be used instead.
- On devices where the L1 cache and shared memory use the same hardware resources, this returns through pCacheConfig the preferred cache configuration for the current device. This is only a preference. The runtime 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 pCacheConfig of musaFuncCachePreferNone on devices where the size of the L1 cache and shared memory are fixed.
- The supported cache configurations are: musaFuncCachePreferNone: no preference for shared memory or L1 (default) musaFuncCachePreferShared: prefer larger shared memory and smaller L1 cache musaFuncCachePreferL1: prefer larger L1 cache and smaller shared memory
Parameters
pCacheConfig(enum musaFuncCache *): Returned cache configuration
Returns
- musaSuccess
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
See also
musaThreadSetCacheConfig
musaError_t musaThreadSetCacheConfig(enum musaFuncCache cacheConfig)
Description
- Sets the preferred cache configuration for the current device.
- Deprecated
- Note that this function is deprecated because its name does not reflect its behavior. Its functionality is identical to the non-deprecated function musaDeviceSetCacheConfig(), which should be used instead.
- On devices where the L1 cache and shared memory use the same hardware resources, this sets through cacheConfig the preferred cache configuration for the current device. This is only a preference. The runtime 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 musaFuncSetCacheConfig (C API) or musaFuncSetCacheConfig (C++ API) will be preferred over this device-wide setting. Setting the device-wide cache configuration to musaFuncCachePreferNone 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: musaFuncCachePreferNone: no preference for shared memory or L1 (default) musaFuncCachePreferShared: prefer larger shared memory and smaller L1 cache musaFuncCachePreferL1: prefer larger L1 cache and smaller shared memory
Parameters
cacheConfig(enum musaFuncCache): Requested cache configuration
Returns
- musaSuccess
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
See also
3.5 Error Handling
musaGetLastError
musaError_t musaGetLastError(void)
Description
- Returns the last error from a runtime call.
- Returns the last error that has been produced by any of the runtime calls in the same instance of the MUSA Runtime library in the host thread and resets it to musaSuccess.
- Note: Multiple instances of the MUSA Runtime library can be present in an application when using a library that statically links the MUSA Runtime.
Parameters
(unnamed)(void)
Returns
- musaSuccess, musaErrorMissingConfiguration, musaErrorMemoryAllocation, musaErrorInitializationError, musaErrorLaunchFailure, musaErrorLaunchTimeout, musaErrorLaunchOutOfResources, musaErrorInvalidDeviceFunction, musaErrorInvalidConfiguration, musaErrorInvalidDevice, musaErrorInvalidValue, musaErrorInvalidPitchValue, musaErrorInvalidSymbol, musaErrorUnmapBufferObjectFailed, musaErrorInvalidDevicePointer, musaErrorInvalidTexture, musaErrorInvalidTextureBinding, musaErrorInvalidChannelDescriptor, musaErrorInvalidMemcpyDirection, musaErrorInvalidFilterSetting, musaErrorInvalidNormSetting, musaErrorUnknown, musaErrorInvalidResourceHandle, musaErrorInsufficientDriver, musaErrorNoDevice, musaErrorSetOnActiveProcess, musaErrorStartupFailure, musaErrorInvalidPtx, musaErrorUnsupportedPtxVersion, musaErrorNoKernelImageForDevice, musaErrorJitCompilerNotFound, musaErrorJitCompilationDisabled
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
See also
- musaPeekAtLastError, musaGetErrorName, musaGetErrorString, musaError
musaPeekAtLastError
musaError_t musaPeekAtLastError(void)
Description
- Returns the last error from a runtime call.
- Returns the last error that has been produced by any of the runtime calls in the same instance of the MUSA Runtime library in the host thread. This call does not reset the error to musaSuccess like musaGetLastError().
- Note: Multiple instances of the MUSA Runtime library can be present in an application when using a library that statically links the MUSA Runtime.
Parameters
(unnamed)(void)
Returns
- musaSuccess, musaErrorMissingConfiguration, musaErrorMemoryAllocation, musaErrorInitializationError, musaErrorLaunchFailure, musaErrorLaunchTimeout, musaErrorLaunchOutOfResources, musaErrorInvalidDeviceFunction, musaErrorInvalidConfiguration, musaErrorInvalidDevice, musaErrorInvalidValue, musaErrorInvalidPitchValue, musaErrorInvalidSymbol, musaErrorUnmapBufferObjectFailed, musaErrorInvalidDevicePointer, musaErrorInvalidTexture, musaErrorInvalidTextureBinding, musaErrorInvalidChannelDescriptor, musaErrorInvalidMemcpyDirection, musaErrorInvalidFilterSetting, musaErrorInvalidNormSetting, musaErrorUnknown, musaErrorInvalidResourceHandle, musaErrorInsufficientDriver, musaErrorNoDevice, musaErrorSetOnActiveProcess, musaErrorStartupFailure, musaErrorInvalidPtx, musaErrorUnsupportedPtxVersion, musaErrorNoKernelImageForDevice, musaErrorJitCompilerNotFound, musaErrorJitCompilationDisabled
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
See also
- musaGetLastError, musaGetErrorName, musaGetErrorString, musaError
musaGetErrorName
const char* musaGetErrorName(musaError_t error)
Description
- Returns the string representation of an error code enum name.
- Returns a string containing the name of an error code in the enum. If the error code is not recognized, "unrecognized error code" is returned.
Parameters
error(musaError_t): Error code to convert to string
Returns
- char* pointer to a NULL-terminated string
See also
- musaGetErrorString, musaGetLastError, musaPeekAtLastError, musaError, muGetErrorName
musaGetErrorString
const char* musaGetErrorString(musaError_t error)
Description
- Returns the description string for an error code.
- Returns the description string for an error code. If the error code is not recognized, "unrecognized error code" is returned.
Parameters
error(musaError_t): Error code to convert to string
Returns
- char* pointer to a NULL-terminated string
See also
- musaGetErrorName, musaGetLastError, musaPeekAtLastError, musaError, muGetErrorString
3.6 Stream Management
musaStreamCreate
musaError_t musaStreamCreate(musaStream_t *pStream)
Description
- Create an asynchronous stream.
- Creates a new asynchronous stream on the context that is current to the calling host thread. If no context is current to the calling host thread, then the primary context for a device is selected, made current to the calling thread, and initialized before creating a stream on it.
Parameters
pStream(musaStream_t *): Pointer to new stream identifier
Returns
- musaSuccess, musaErrorInvalidValue
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
See also
- musaStreamCreateWithPriority, musaStreamCreateWithFlags, musaStreamGetPriority, musaStreamGetFlags, musaStreamGetDevice, musaStreamQuery, musaStreamSynchronize, musaStreamWaitEvent, musaStreamAddCallback, musaSetDevice, musaStreamDestroy, muStreamCreate
musaStreamCreateWithFlags
musaError_t musaStreamCreateWithFlags(musaStream_t *pStream, unsigned int flags)
Description
- Create an asynchronous stream.
- Creates a new asynchronous stream on the context that is current to the calling host thread. If no context is current to the calling host thread, then the primary context for a device is selected, made current to the calling thread, and initialized before creating a stream on it. The flags argument determines the behaviors of the stream. Valid values for flags are musaStreamDefault: Default stream creation flag. musaStreamNonBlocking: 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
pStream(musaStream_t *): Pointer to new stream identifierflags(unsigned int): Parameters for stream creation
Returns
- musaSuccess, musaErrorInvalidValue
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
See also
- musaStreamCreate, musaStreamCreateWithPriority, musaStreamGetFlags, musaStreamGetDevice, musaStreamQuery, musaStreamSynchronize, musaStreamWaitEvent, musaStreamAddCallback, musaSetDevice, musaStreamDestroy, muStreamCreate
musaStreamCreateWithPriority
musaError_t musaStreamCreateWithPriority(musaStream_t *pStream, unsigned int flags, int priority)
Description
- Create an asynchronous stream with the specified priority.
- Creates a stream with the specified priority and returns a handle in pStream. The stream is created on the context that is current to the calling host thread. If no context is current to the calling host thread, then the primary context for a device is selected, made current to the calling thread, and initialized before creating a stream on it. 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 musaDeviceGetStreamPriorityRange. If the specified priority is outside the numerical range returned by musaDeviceGetStreamPriorityRange, it will automatically be clamped to the lowest or the highest number in the range.
Parameters
pStream(musaStream_t *): Pointer to new stream identifierflags(unsigned int): Flags for stream creation. See musaStreamCreateWithFlags for a list of valid flags that can be passedpriority(int): Priority of the stream. Lower numbers represent higher priorities. See musaDeviceGetStreamPriorityRange for more information about the meaningful stream priorities that can be passed.
Returns
- musaSuccess, musaErrorInvalidValue
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
- 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
- musaStreamCreate, musaStreamCreateWithFlags, musaDeviceGetStreamPriorityRange, musaStreamGetPriority, musaStreamQuery, musaStreamWaitEvent, musaStreamAddCallback, musaStreamSynchronize, musaSetDevice, musaStreamDestroy, muStreamCreateWithPriority
musaStreamGetPriority
musaError_t musaStreamGetPriority(musaStream_t hStream, int *priority)
Description
- Query the priority of a stream.
- Query the priority of a stream. The priority is returned in in priority. Note that if the stream was created with a priority outside the meaningful numerical range returned by musaDeviceGetStreamPriorityRange, this function returns the clamped priority. See musaStreamCreateWithPriority for details about priority clamping.
Parameters
hStream(musaStream_t): Handle to the stream to be queriedpriority(int *): Pointer to a signed integer in which the stream's priority is returned
Returns
- musaSuccess, musaErrorInvalidValue, musaErrorInvalidResourceHandle
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
See also
- musaStreamCreateWithPriority, musaDeviceGetStreamPriorityRange, musaStreamGetFlags, musaStreamGetDevice, muStreamGetPriority
musaStreamGetFlags
musaError_t musaStreamGetFlags(musaStream_t hStream, unsigned int *flags)
Description
- Query the flags of a stream.
- Query the flags of a stream. The flags are returned in flags. See musaStreamCreateWithFlags for a list of valid flags.
Parameters
hStream(musaStream_t): Handle to the stream to be queriedflags(unsigned int *): Pointer to an unsigned integer in which the stream's flags are returned
Returns
- musaSuccess, musaErrorInvalidValue, musaErrorInvalidResourceHandle
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
- See the default-stream note for NULL stream semantics.
See also
- musaStreamCreateWithPriority, musaStreamCreateWithFlags, musaStreamGetPriority, musaStreamGetDevice, muStreamGetFlags
musaStreamGetId
musaError_t musaStreamGetId(musaStream_t hStream, unsigned long long *streamId)
Description
- Query the Id of a stream.
- Query the Id of a stream. The Id is returned in streamId. 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 runtime APIs such as musaStreamCreate, musaStreamCreateWithFlags and musaStreamCreateWithPriority, or their driver API equivalents such as muStreamCreate or muStreamCreateWithPriority. Passing an invalid handle will result in undefined behavior. any of the special streams such as the NULL stream, musaStreamLegacy and musaStreamPerThread respectively. The driver API equivalents of these are also accepted which are NULL, MU_STREAM_LEGACY and MU_STREAM_PER_THREAD.
Parameters
hStream(musaStream_t): Handle to the stream to be queriedstreamId(unsigned long long *): Pointer to an unsigned long long in which the stream Id is returned
Returns
- musaSuccess, musaErrorInvalidValue, musaErrorInvalidResourceHandle
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
- See the default-stream note for NULL stream semantics.
See also
- musaStreamCreateWithPriority, musaStreamCreateWithFlags, musaStreamGetPriority, musaStreamGetFlags, muStreamGetId
musaStreamGetDevice
musaError_t musaStreamGetDevice(musaStream_t hStream, int *device)
Description
- Query the device of a stream.
- Returns in *device the device of the stream.
Parameters
hStream(musaStream_t): Handle to the stream to be querieddevice(int *): Returns the device to which the stream belongs
Returns
- musaSuccess, musaErrorInvalidValue, musaErrorDeviceUnavailable
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
- See the default-stream note for NULL stream semantics.
See also
- musaSetDevice, musaGetDevice, musaStreamCreate, musaStreamGetPriority, musaStreamGetFlags, muStreamGetId
musaCtxResetPersistingL2Cache
musaError_t musaCtxResetPersistingL2Cache(void)
Description
- Resets all persisting lines in cache to normal status.
- Resets all persisting lines in cache to normal status. Takes effect on function return.
Parameters
(unnamed)(void)
Returns
- musaSuccess
Note
- This function may also return error codes from previous, asynchronous launches.
See also
- musaAccessPolicyWindow
musaStreamCopyAttributes
musaError_t musaStreamCopyAttributes(musaStream_t dst, musaStream_t 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(musaStream_t): Destination streamsrc(musaStream_t): Source stream For attributes see musaStreamAttrID
Returns
- musaSuccess, musaErrorNotSupported
Note
- This function may also return error codes from previous, asynchronous launches.
See also
- musaAccessPolicyWindow
musaStreamGetAttribute
musaError_t musaStreamGetAttribute(musaStream_t hStream, musaStreamAttrID attr, musaStreamAttrValue *value_out)
Description
- Queries stream attribute.
- Queries attribute attr from hStream and stores it in corresponding member of value_out.
Parameters
hStream(musaStream_t)attr(musaStreamAttrID)value_out(musaStreamAttrValue *)
Returns
- musaSuccess, musaErrorInvalidValue, musaErrorInvalidResourceHandle
Note
- This function may also return error codes from previous, asynchronous launches.
See also
- musaAccessPolicyWindow
musaStreamSetAttribute
musaError_t musaStreamSetAttribute(musaStream_t hStream, musaStreamAttrID attr, const musaStreamAttrValue *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(musaStream_t)attr(musaStreamAttrID)value(const musaStreamAttrValue *)
Returns
- musaSuccess, musaErrorInvalidValue, musaErrorInvalidResourceHandle
Note
- This function may also return error codes from previous, asynchronous launches.
See also
- musaAccessPolicyWindow
musaStreamDestroy
musaError_t musaStreamDestroy(musaStream_t stream)
Description
- Destroys and cleans up an asynchronous stream.
- Destroys and cleans up the asynchronous stream specified by stream.
- In case the device is still doing work in the stream stream when musaStreamDestroy() is called, the function will return immediately and the resources associated with stream will be released automatically once the device has completed all work in stream.
Parameters
stream(musaStream_t): Stream identifier
Returns
- musaSuccess, musaErrorInvalidValue, musaErrorInvalidResourceHandle
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
- Destroying the target object while work is still pending results in undefined behavior.
- See the default-stream note for NULL stream semantics.
See also
- musaStreamCreate, musaStreamCreateWithFlags, musaStreamQuery, musaStreamWaitEvent, musaStreamSynchronize, musaStreamAddCallback, muStreamDestroy
musaStreamWaitEvent
musaError_t musaStreamWaitEvent(musaStream_t stream, musaEvent_t event, unsigned int flags)
Description
- Make a compute stream wait on an event.
- Makes all future work submitted to stream wait for all work captured in event. See musaEventRecord() for details on what is captured by an event. The synchronization will be performed efficiently on the device when applicable. event may be from a different device than stream.
- flags include: musaEventWaitDefault: Default event creation flag. musaEventWaitExternal: Event is captured in the graph as an external event node when performing stream capture.
Parameters
stream(musaStream_t): Stream to waitevent(musaEvent_t): Event to wait onflags(unsigned int): Parameters for the operation(See above)
Returns
- musaSuccess, musaErrorInvalidValue, musaErrorInvalidResourceHandle
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
- See the default-stream note for NULL stream semantics.
See also
- musaStreamCreate, musaStreamCreateWithFlags, musaStreamQuery, musaStreamSynchronize, musaStreamAddCallback, musaStreamDestroy, muStreamWaitEvent
musaStreamAddCallback
musaError_t musaStreamAddCallback(musaStream_t stream, musaStreamCallback_t callback, void *userData, unsigned int flags)
Description
- Add a callback to a compute stream.
- The callback may be passed musaSuccess or an error code. In the event of a device error, all subsequently executed callbacks will receive an appropriate musaError_t.
- Callbacks must not make any MUSA API calls. Attempting to use MUSA APIs may result in musaErrorNotPermitted. 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 callbacks have executed. Thus, for example, a callback might use global attached memory even if work has been added to another stream, if it has been properly ordered 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
stream(musaStream_t): Stream to add callback tocallback(musaStreamCallback_t): 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
- musaSuccess, musaErrorInvalidResourceHandle, musaErrorInvalidValue, musaErrorNotSupported
Note
- 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 musaLaunchHostFunc. Additionally, this function is not supported with musaStreamBeginCapture and musaStreamEndCapture, unlike musaLaunchHostFunc.
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
- See the default-stream note for NULL stream semantics.
See also
- musaStreamCreate, musaStreamCreateWithFlags, musaStreamQuery, musaStreamSynchronize, musaStreamWaitEvent, musaStreamDestroy, musaMallocManaged, musaStreamAttachMemAsync, musaLaunchHostFunc, muStreamAddCallback
musaStreamSynchronize
musaError_t musaStreamSynchronize(musaStream_t stream)
Description
- Waits for stream tasks to complete.
- Blocks until stream has completed all operations. If the musaDeviceScheduleBlockingSync flag was set for this device, the host thread will block until the stream is finished with all of its tasks.
Parameters
stream(musaStream_t): Stream identifier
Returns
- musaSuccess, musaErrorInvalidResourceHandle
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
- See the default-stream note for NULL stream semantics.
See also
- musaStreamCreate, musaStreamCreateWithFlags, musaStreamQuery, musaStreamWaitEvent, musaStreamAddCallback, musaStreamDestroy, muStreamSynchronize
musaStreamQuery
musaError_t musaStreamQuery(musaStream_t stream)
Description
- Queries an asynchronous stream for completion status.
- Returns musaSuccess if all operations in stream have completed, or musaErrorNotReady if not.
- For the purposes of Unified Memory, a return value of musaSuccess is equivalent to having called musaStreamSynchronize().
Parameters
stream(musaStream_t): Stream identifier
Returns
- musaSuccess, musaErrorNotReady, musaErrorInvalidResourceHandle
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
- See the default-stream note for NULL stream semantics.
See also
- musaStreamCreate, musaStreamCreateWithFlags, musaStreamWaitEvent, musaStreamSynchronize, musaStreamAddCallback, musaStreamDestroy, muStreamQuery
musaStreamAttachMemAsync
musaError_t musaStreamAttachMemAsync(musaStream_t stream, void *devPtr, size_t length, unsigned int flags)
Description
- Attach memory to a stream asynchronously.
- Enqueues an operation in stream to specify stream association of length bytes of memory starting from devPtr. 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.
- devPtr must point to an one of the following types of memories: managed memory declared using the managed keyword or allocated with musaMallocManaged. 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 musaDevAttrPageableMemoryAccess.
- 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 allocations, length must be non-zero.
- The stream association is specified using flags which must be one of musaMemAttachGlobal, musaMemAttachHost or musaMemAttachSingle. The default value for flags is musaMemAttachSingle If the musaMemAttachGlobal flag is specified, the memory can be accessed by any stream on any device. If the musaMemAttachHost 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 musaDevAttrConcurrentManagedAccess. If the musaMemAttachSingle flag is specified and stream is associated with a device that has a zero value for the device attribute musaDevAttrConcurrentManagedAccess, the program makes a guarantee that it will only access the memory on the device from stream. 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 stream 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 musaStreamAttachMemAsync 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 stream 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 musaMallocManaged. For managed variables, the default association is always musaMemAttachGlobal. 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
stream(musaStream_t): Stream in which to enqueue the attach operationdevPtr(void *): Pointer to memory (must be a pointer to managed memory or to a valid host-accessible region of system-allocated memory)length(size_t): Length of memory (defaults to zero)flags(unsigned int): Must be one of musaMemAttachGlobal, musaMemAttachHost or musaMemAttachSingle (defaults to musaMemAttachSingle)
Returns
- musaSuccess, musaErrorNotReady, musaErrorInvalidValue, musaErrorInvalidResourceHandle
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
See also
- musaStreamCreate, musaStreamCreateWithFlags, musaStreamWaitEvent, musaStreamSynchronize, musaStreamAddCallback, musaStreamDestroy, musaMallocManaged, muStreamAttachMemAsync
musaStreamBeginCapture
musaError_t musaStreamBeginCapture(musaStream_t stream, enum musaStreamCaptureMode mode)
Description
- Begins graph capture on a stream.
- Begin graph capture on stream. 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 musaStreamEndCapture. Capture may not be initiated if stream is musaStreamLegacy. 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 musaStreamIsCapturing. A unique id representing the capture sequence may be queried via musaStreamGetCaptureInfo.
- If mode is not musaStreamCaptureModeRelaxed, musaStreamEndCapture must be called on this stream from the same thread.
Parameters
stream(musaStream_t): Stream in which to initiate capturemode(enum musaStreamCaptureMode): Controls the interaction of this capture sequence with other API calls that are potentially unsafe. For more details see musaThreadExchangeStreamCaptureMode.
Returns
- musaSuccess, musaErrorInvalidValue
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
musaStreamBeginCaptureToGraph
musaError_t musaStreamBeginCaptureToGraph(musaStream_t stream, musaGraph_t graph, const musaGraphNode_t *dependencies, const musaGraphEdgeData *dependencyData, size_t numDependencies, enum musaStreamCaptureMode mode)
Description
- Begins graph capture on a stream to an existing graph.
- Begin graph capture on stream. When a stream is in capture mode, all operations pushed into the stream will not be executed, but will instead be captured into graph, which will be returned via musaStreamEndCapture.
- Capture may not be initiated if stream is musaStreamLegacy. 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 musaStreamIsCapturing. A unique id representing the capture sequence may be queried via musaStreamGetCaptureInfo.
- If mode is not musaStreamCaptureModeRelaxed, musaStreamEndCapture must be called on this stream from the same thread.
Parameters
stream(musaStream_t): Stream in which to initiate capture.graph(musaGraph_t): Graph to capture into.dependencies(const musaGraphNode_t *): Dependencies of the first node captured in the stream. Can be NULL if numDependencies is 0.dependencyData(const musaGraphEdgeData *): Optional array of data associated with each dependency.numDependencies(size_t): Number of dependencies.mode(enum musaStreamCaptureMode): Controls the interaction of this capture sequence with other API calls that are potentially unsafe. For more details see musaThreadExchangeStreamCaptureMode.
Returns
- musaSuccess, musaErrorInvalidValue
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
musaThreadExchangeStreamCaptureMode
musaError_t musaThreadExchangeStreamCaptureMode(enum musaStreamCaptureMode *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:musaStreamCaptureModemode=desiredMode; musaThreadExchangeStreamCaptureMode(&mode); ... musaThreadExchangeStreamCaptureMode(&mode);//restorepreviousmode
- During stream capture (see musaStreamBeginCapture), 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 musaStreamBeginCapture 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 musaStreamBeginCapture-musaStreamEndCapture sequence. This behavior can be controlled via this API and flags to musaStreamBeginCapture.
- A thread's mode is one of the following: musaStreamCaptureModeGlobal: This is the default mode. If the local thread has an ongoing capture sequence that was not initiated with musaStreamCaptureModeRelaxed at muStreamBeginCapture, or if any other thread has a concurrent capture sequence initiated with musaStreamCaptureModeGlobal, this thread is prohibited from potentially unsafe API calls. musaStreamCaptureModeThreadLocal: If the local thread has an ongoing capture sequence not initiated with musaStreamCaptureModeRelaxed, it is prohibited from potentially unsafe API calls. Concurrent capture sequences in other threads are ignored. musaStreamCaptureModeRelaxed: 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 musaEventQuery on an event that was last recorded inside a capture sequence.
Parameters
mode(enum musaStreamCaptureMode *): Pointer to mode value to swap with the current mode
Returns
- musaSuccess, musaErrorInvalidValue
Note
- This function may also return error codes from previous, asynchronous launches.
See also
musaStreamEndCapture
musaError_t musaStreamEndCapture(musaStream_t stream, musaGraph_t *pGraph)
Description
- Ends capture on a stream, returning the captured graph.
- End capture on stream, returning the captured graph via pGraph. Capture must have been initiated on stream via a call to musaStreamBeginCapture. 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 musaStreamBeginCapture was not musaStreamCaptureModeRelaxed, this call must be from the same thread as musaStreamBeginCapture.
Parameters
stream(musaStream_t): Stream to querypGraph(musaGraph_t *): The captured graph
Returns
- musaSuccess, musaErrorInvalidValue, musaErrorStreamCaptureWrongThread
Note
- This function may also return error codes from previous, asynchronous launches.
See also
musaStreamIsCapturing
musaError_t musaStreamIsCapturing(musaStream_t stream, enum musaStreamCaptureStatus *pCaptureStatus)
Description
- Returns a stream's capture status.
- Return the capture status of stream via pCaptureStatus. After a successful call, *pCaptureStatus will contain one of the following: musaStreamCaptureStatusNone: The stream is not capturing. musaStreamCaptureStatusActive: The stream is capturing. musaStreamCaptureStatusInvalidated: The stream was capturing but an error has invalidated the capture sequence. The capture sequence must be terminated with musaStreamEndCapture on the stream where it was initiated in order to continue using stream.
- Note that, if this is called on musaStreamLegacy (the "null stream") while a blocking stream on the same device is capturing, it will return musaErrorStreamCaptureImplicit and *pCaptureStatus 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
stream(musaStream_t): Stream to querypCaptureStatus(enum musaStreamCaptureStatus *): Returns the stream's capture status
Returns
- musaSuccess, musaErrorInvalidValue, musaErrorStreamCaptureImplicit
Note
- This function may also return error codes from previous, asynchronous launches.
See also
musaStreamGetCaptureInfo
musaError_t musaStreamGetCaptureInfo(musaStream_t stream, enum musaStreamCaptureStatus *captureStatus_out, unsigned long long *id_out, musaGraph_t *graph_out, const musaGraphNode_t **dependencies_out, size_t *numDependencies_out)
Description
- Query a stream's capture state.
- Query stream state related to stream capture.
- If called on musaStreamLegacy (the "null stream") while a stream not created with musaStreamNonBlocking is capturing, returns musaErrorStreamCaptureImplicit.
- Valid data (other than capture status) is returned only if both of the following are true: the call returns musaSuccess the returned capture status is musaStreamCaptureStatusActive
Parameters
stream(musaStream_t): The stream to querycaptureStatus_out(enum musaStreamCaptureStatus *): Location to return the capture status of the stream; requiredid_out(unsigned long long *): Optional location to return an id for the capture sequence, which is unique over the lifetime of the processgraph_out(musaGraph_t *): 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 musaStreamEndCapture. 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 musaStreamEndCapture due to direct actions on the graph do not trigger musaErrorStreamCaptureUnjoined.dependencies_out(const musaGraphNode_t **): 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
- musaSuccess, musaErrorInvalidValue, musaErrorStreamCaptureImplicit
Note
- Additional exported symbol names in scope:
musaStreamGetCaptureInfo_v2. - This function may also return error codes from previous, asynchronous launches.
- Graph objects are not thread-safe.
See also
- musaStreamGetCaptureInfo_v3, musaStreamBeginCapture, musaStreamIsCapturing, musaStreamUpdateCaptureDependencies
musaStreamGetCaptureInfo_v3
musaError_t musaStreamGetCaptureInfo_v3(musaStream_t stream, enum musaStreamCaptureStatus *captureStatus_out, unsigned long long *id_out, musaGraph_t *graph_out, const musaGraphNode_t **dependencies_out, const musaGraphEdgeData **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 musaStreamLegacy (the "null stream") while a stream not created with musaStreamNonBlocking is capturing, returns musaErrorStreamCaptureImplicit.
- Valid data (other than capture status) is returned only if both of the following are true: the call returns musaSuccess the returned capture status is musaStreamCaptureStatusActive
- 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 musaErrorLossyQuery.
Parameters
stream(musaStream_t): The stream to querycaptureStatus_out(enum musaStreamCaptureStatus *): Location to return the capture status of the stream; requiredid_out(unsigned long long *): Optional location to return an id for the capture sequence, which is unique over the lifetime of the processgraph_out(musaGraph_t *): 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 musaStreamEndCapture. 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 musaStreamEndCapture due to direct actions on the graph do not trigger musaErrorStreamCaptureUnjoined.dependencies_out(const musaGraphNode_t **): 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 musaGraphEdgeData **): 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
- musaSuccess, musaErrorInvalidValue, musaErrorStreamCaptureImplicit, musaErrorLossyQuery
Note
- This function may also return error codes from previous, asynchronous launches.
- Graph objects are not thread-safe.
See also
musaStreamUpdateCaptureDependencies
musaError_t musaStreamUpdateCaptureDependencies(musaStream_t stream, musaGraphNode_t *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 musaStreamAddCaptureDependencies and musaStreamSetCaptureDependencies. 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 musaStreamAddCaptureDependencies.
- Nodes that are removed from the dependency set via this API do not result in musaErrorStreamCaptureUnjoined if they are unreachable from the stream at musaStreamEndCapture.
- Returns musaErrorIllegalState if the stream is not capturing.
- This API is new in MUSA 11.3. Developers requiring compatibility across minor versions of the MUSA driver to 11.0 should not use this API or provide a fallback.
Parameters
stream(musaStream_t): The stream to updatedependencies(musaGraphNode_t *): The set of dependencies to addnumDependencies(size_t): The size of the dependencies arrayflags(unsigned int): See above
Returns
- musaSuccess, musaErrorInvalidValue, musaErrorIllegalState
Note
- This function may also return error codes from previous, asynchronous launches.
See also
3.7 Event Management
musaEventCreate
musaError_t musaEventCreate(musaEvent_t *event)
Description
- Creates an event object.
- Creates an event object for the current device using musaEventDefault.
Parameters
event(musaEvent_t *): Newly created event
Returns
- musaSuccess, musaErrorInvalidValue, musaErrorLaunchFailure, musaErrorMemoryAllocation
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
See also
- musaEventCreate (C++ API), musaEventCreateWithFlags, musaEventRecord, musaEventQuery, musaEventSynchronize, musaEventDestroy, musaEventElapsedTime, musaStreamWaitEvent, muEventCreate
musaEventCreateWithFlags
musaError_t musaEventCreateWithFlags(musaEvent_t *event, unsigned int flags)
Description
- Creates an event object with the specified flags.
- Creates an event object for the current device with the specified flags. Valid flags include: musaEventDefault: Default event creation flag. musaEventBlockingSync: Specifies that event should use blocking synchronization. A host thread that uses musaEventSynchronize() to wait on an event created with this flag will block until the event actually completes. musaEventDisableTiming: Specifies that the created event does not need to record timing data. Events created with this flag specified and the musaEventBlockingSync flag not specified will provide the best performance when used with musaStreamWaitEvent() and musaEventQuery(). musaEventInterprocess: Specifies that the created event may be used as an interprocess event by musaIpcGetEventHandle(). musaEventInterprocess must be specified along with musaEventDisableTiming.
Parameters
event(musaEvent_t *): Newly created eventflags(unsigned int): Flags for new event
Returns
- musaSuccess, musaErrorInvalidValue, musaErrorLaunchFailure, musaErrorMemoryAllocation
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
See also
- musaEventCreate (C API), musaEventSynchronize, musaEventDestroy, musaEventElapsedTime, musaStreamWaitEvent, muEventCreate
musaEventRecord
musaError_t musaEventRecord(musaEvent_t event, musaStream_t stream)
Description
- Records an event.
- Captures in event the contents of stream at the time of this call. event and stream must be on the same MUSA context. Calls such as musaEventQuery() or musaStreamWaitEvent() will then examine or wait for completion of the work that was captured. Uses of stream after this call do not modify event. See note on default stream behavior for what is captured in the default case.
- musaEventRecord() can be called multiple times on the same event and will overwrite the previously captured state. Other APIs such as musaStreamWaitEvent() use the most recently captured state at the time of the API call, and are not affected by later calls to musaEventRecord(). Before the first call to musaEventRecord(), an event represents an empty set of work, so for example musaEventQuery() would return musaSuccess.
Parameters
event(musaEvent_t): Event to recordstream(musaStream_t): Stream in which to record event
Returns
- musaSuccess, musaErrorInvalidValue, musaErrorInvalidResourceHandle, musaErrorLaunchFailure
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
- See the default-stream note for NULL stream semantics.
- See the event note for NULL event semantics.
See also
- musaEventCreate (C API), musaEventCreateWithFlags, musaEventQuery, musaEventSynchronize, musaEventDestroy, musaEventElapsedTime, musaStreamWaitEvent, musaEventRecordWithFlags, muEventRecord
musaEventRecordWithFlags
musaError_t musaEventRecordWithFlags(musaEvent_t event, musaStream_t stream, unsigned int flags)
Description
- Records an event.
- Captures in event the contents of stream at the time of this call. event and stream must be on the same MUSA context. Calls such as musaEventQuery() or musaStreamWaitEvent() will then examine or wait for completion of the work that was captured. Uses of stream after this call do not modify event. See note on default stream behavior for what is captured in the default case.
- musaEventRecordWithFlags() can be called multiple times on the same event and will overwrite the previously captured state. Other APIs such as musaStreamWaitEvent() use the most recently captured state at the time of the API call, and are not affected by later calls to musaEventRecordWithFlags(). Before the first call to musaEventRecordWithFlags(), an event represents an empty set of work, so for example musaEventQuery() would return musaSuccess.
- flags include: musaEventRecordDefault: Default event creation flag. musaEventRecordExternal: Event is captured in the graph as an external event node when performing stream capture.
Parameters
event(musaEvent_t): Event to recordstream(musaStream_t): Stream in which to record eventflags(unsigned int): Parameters for the operation(See above)
Returns
- musaSuccess, musaErrorInvalidValue, musaErrorInvalidResourceHandle, musaErrorLaunchFailure
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
- See the default-stream note for NULL stream semantics.
- See the event note for NULL event semantics.
See also
- musaEventCreate (C API), musaEventCreateWithFlags, musaEventQuery, musaEventSynchronize, musaEventDestroy, musaEventElapsedTime, musaStreamWaitEvent, musaEventRecord, muEventRecord,
musaEventQuery
musaError_t musaEventQuery(musaEvent_t event)
Description
- Queries an event's status.
- Queries the status of all work currently captured by event. See musaEventRecord() for details on what is captured by an event.
- Returns musaSuccess if all captured work has been completed, or musaErrorNotReady if any captured work is incomplete.
- For the purposes of Unified Memory, a return value of musaSuccess is equivalent to having called musaEventSynchronize().
Parameters
event(musaEvent_t): Event to query
Returns
- musaSuccess, musaErrorNotReady, musaErrorInvalidValue, musaErrorInvalidResourceHandle, musaErrorLaunchFailure
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
- See the event note for NULL event semantics.
See also
- musaEventCreate (C API), musaEventCreateWithFlags, musaEventRecord, musaEventSynchronize, musaEventDestroy, musaEventElapsedTime, muEventQuery
musaEventSynchronize
musaError_t musaEventSynchronize(musaEvent_t event)
Description
- Waits for an event to complete.
- Waits until the completion of all work currently captured in event. See musaEventRecord() for details on what is captured by an event.
- Waiting for an event that was created with the musaEventBlockingSync flag will cause the calling CPU thread to block until the event has been completed by the device. If the musaEventBlockingSync flag has not been set, then the CPU thread will busy-wait until the event has been completed by the device.
Parameters
event(musaEvent_t): Event to wait for
Returns
- musaSuccess, musaErrorInvalidValue, musaErrorInvalidResourceHandle, musaErrorLaunchFailure
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
- See the event note for NULL event semantics.
See also
- musaEventCreate (C API), musaEventCreateWithFlags, musaEventRecord, musaEventQuery, musaEventDestroy, musaEventElapsedTime, muEventSynchronize
musaEventDestroy
musaError_t musaEventDestroy(musaEvent_t event)
Description
- Destroys an event object.
- Destroys the event specified by event.
- An event may be destroyed before it is complete (i.e., while musaEventQuery() would return musaErrorNotReady). 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
event(musaEvent_t): Event to destroy
Returns
- musaSuccess, musaErrorInvalidValue, musaErrorInvalidResourceHandle, musaErrorLaunchFailure
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
- Destroying the target object while work is still pending results in undefined behavior.
- See the event note for NULL event semantics.
See also
- musaEventCreate (C API), musaEventCreateWithFlags, musaEventQuery, musaEventSynchronize, musaEventRecord, musaEventElapsedTime, muEventDestroy
musaEventElapsedTime
musaError_t musaEventElapsedTime(float *ms, musaEvent_t start, musaEvent_t end)
Description
- Computes the elapsed time between 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 musaEventRecord() 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 musaEventRecord() has not been called on either event, then musaErrorInvalidResourceHandle is returned. If musaEventRecord() has been called on both events but one or both of them has not yet been completed (that is, musaEventQuery() would return musaErrorNotReady on at least one of the events), musaErrorNotReady is returned. If either event was created with the musaEventDisableTiming flag, then this function will return musaErrorInvalidResourceHandle.
Parameters
ms(float *): Time between start and end in msstart(musaEvent_t): Starting eventend(musaEvent_t): Ending event
Returns
- musaSuccess, musaErrorNotReady, musaErrorInvalidValue, musaErrorInvalidResourceHandle, musaErrorLaunchFailure, musaErrorUnknown
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
- See the event note for NULL event semantics.
See also
- musaEventCreate (C API), musaEventCreateWithFlags, musaEventQuery, musaEventSynchronize, musaEventDestroy, musaEventRecord, muEventElapsedTime
musaEventElapsedTime_v2
musaError_t musaEventElapsedTime_v2(float *ms, musaEvent_t start, musaEvent_t end)
Description
- Computes the elapsed time between 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 a elapsed time calculation only and polling for completion on the events to be compared should be done with musaEventQuery 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 musaEventRecord() 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 musaEventRecord() has not been called on either event, then musaErrorInvalidResourceHandle is returned. If musaEventRecord() has been called on both events but one or both of them has not yet been completed (that is, musaEventQuery() would return musaErrorNotReady on at least one of the events), musaErrorNotReady is returned. If either event was created with the musaEventDisableTiming flag, then this function will return musaErrorInvalidResourceHandle.
Parameters
ms(float *): Time between start and end in msstart(musaEvent_t): Starting eventend(musaEvent_t): Ending event
Returns
- musaSuccess, musaErrorNotReady, musaErrorInvalidValue, musaErrorInvalidResourceHandle, musaErrorLaunchFailure, musaErrorUnknown
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
- See the event note for NULL event semantics.
See also
- musaEventCreate (C API), musaEventCreateWithFlags, musaEventQuery, musaEventSynchronize, musaEventDestroy, musaEventRecord, muEventElapsedTime
3.8 External Resource Interoperability
musaImportExternalMemory
musaError_t musaImportExternalMemory(musaExternalMemory_t *extMem_out, const struct musaExternalMemoryHandleDesc *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 musaExternalMemoryHandleDesc structure is defined as follows:
typedef struct musaExternalMemoryHandleDesc_st {
musaExternalMemoryHandleTypetype;
union {
int fd;
struct {
void *handle;
const void *name;
} win32;
const void *mtSciBufObject;
} handle;
unsigned long long size;
unsigned int flags;
} musaExternalMemoryHandleDesc;
- where musaExternalMemoryHandleDesc::type specifies the type of handle being imported. musaExternalMemoryHandleType is defined as:
typedef enum musaExternalMemoryHandleType_enum {
musaExternalMemoryHandleTypeOpaqueFd = 1,
musaExternalMemoryHandleTypeOpaqueWin32 = 2,
musaExternalMemoryHandleTypeOpaqueWin32Kmt = 3,
musaExternalMemoryHandleTypeD3D12Heap = 4,
musaExternalMemoryHandleTypeD3D12Resource = 5,
musaExternalMemoryHandleTypeD3D11Resource = 6,
musaExternalMemoryHandleTypeD3D11ResourceKmt = 7,
musaExternalMemoryHandleTypeMtSciBuf = 8;
} musaExternalMemoryHandleType;
- If musaExternalMemoryHandleDesc::type is musaExternalMemoryHandleTypeOpaqueFd, then musaExternalMemoryHandleDesc::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 musaExternalMemoryHandleDesc::type is musaExternalMemoryHandleTypeOpaqueWin32, then exactly one of musaExternalMemoryHandleDesc::handle::win32::handle and musaExternalMemoryHandleDesc::handle::win32::name must not be NULL. If musaExternalMemoryHandleDesc::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 musaExternalMemoryHandleDesc::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 musaExternalMemoryHandleDesc::type is musaExternalMemoryHandleTypeOpaqueWin32Kmt, then musaExternalMemoryHandleDesc::handle::win32::handle must be non-NULL and musaExternalMemoryHandleDesc::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 musaExternalMemoryHandleDesc::type is musaExternalMemoryHandleTypeD3D12Heap, then exactly one of musaExternalMemoryHandleDesc::handle::win32::handle and musaExternalMemoryHandleDesc::handle::win32::name must not be NULL. If musaExternalMemoryHandleDesc::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 musaExternalMemoryHandleDesc::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 musaExternalMemoryHandleDesc::type is musaExternalMemoryHandleTypeD3D12Resource, then exactly one of musaExternalMemoryHandleDesc::handle::win32::handle and musaExternalMemoryHandleDesc::handle::win32::name must not be NULL. If musaExternalMemoryHandleDesc::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 musaExternalMemoryHandleDesc::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 musaExternalMemoryHandleDesc::type is musaExternalMemoryHandleTypeD3D11Resource,then exactly one of musaExternalMemoryHandleDesc::handle::win32::handle and musaExternalMemoryHandleDesc::handle::win32::name must not be NULL. If musaExternalMemoryHandleDesc::handle::win32::handle is not NULL, then it must represent a valid shared NT handle that is returned by IDXGIResource1::CreateSharedHandle when referring to a ID3D11Resource object. If musaExternalMemoryHandleDesc::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 musaExternalMemoryHandleDesc::type is musaExternalMemoryHandleTypeD3D11ResourceKmt, then musaExternalMemoryHandleDesc::handle::win32::handle must be non-NULL and musaExternalMemoryHandleDesc::handle::win32::name must be NULL. The handle specified must be a valid shared KMT handle that is returned by IDXGIResource::GetSharedHandle when referring to a ID3D11Resource object.
- If musaExternalMemoryHandleDesc::type is musaExternalMemoryHandleTypeMtSciBuf, then musaExternalMemoryHandleDesc::handle::mtSciBufObject must be NON-NULL and reference a valid MtSciBuf object. If the MtSciBuf object imported into MUSA is also mapped by other drivers, then the application must use musaWaitExternalSemaphoresAsync or musaSignalExternalSemaphoresAsync as approprriate barriers to maintain coherence between MUSA and the other drivers. See musaExternalSemaphoreWaitSkipMtSciBufMemSync and musaExternalSemaphoreSignalSkipMtSciBufMemSync for memory synchronization.
- The size of the memory object must be specified in musaExternalMemoryHandleDesc::size.
- Specifying the flag musaExternalMemoryDedicated in musaExternalMemoryHandleDesc::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 musaExternalMemoryHandleDesc::type is one of the following: musaExternalMemoryHandleTypeD3D12Resource musaExternalMemoryHandleTypeD3D11Resource musaExternalMemoryHandleTypeD3D11ResourceKmt
Parameters
extMem_out(musaExternalMemory_t *): Returned handle to an external memory objectmemHandleDesc(const struct musaExternalMemoryHandleDesc *): Memory import handle descriptor
Returns
- musaSuccess, musaErrorInvalidValue, musaErrorInvalidResourceHandle, musaErrorOperatingSystem
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
- 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
- musaDestroyExternalMemory, musaExternalMemoryGetMappedBuffer, musaExternalMemoryGetMappedMipmappedArray
musaExternalMemoryGetMappedBuffer
musaError_t musaExternalMemoryGetMappedBuffer(void **devPtr, musaExternalMemory_t extMem, const struct musaExternalMemoryBufferDesc *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 musaExternalMemoryBufferDesc structure is defined as follows:
typedef struct musaExternalMemoryBufferDesc_st {
unsigned long long offset;
unsigned long long size;
unsigned int flags;
} musaExternalMemoryBufferDesc;
- where musaExternalMemoryBufferDesc::offset is the offset in the memory object where the buffer's base address is. musaExternalMemoryBufferDesc::size is the size of the buffer. musaExternalMemoryBufferDesc::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 musaFree.
Parameters
devPtr(void **): Returned device pointer to bufferextMem(musaExternalMemory_t): Handle to external memory objectbufferDesc(const struct musaExternalMemoryBufferDesc *): Buffer descriptor
Returns
- musaSuccess, musaErrorInvalidValue, musaErrorInvalidResourceHandle
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
See also
musaExternalMemoryGetMappedMipmappedArray
musaError_t musaExternalMemoryGetMappedMipmappedArray(musaMipmappedArray_t *mipmap, musaExternalMemory_t extMem, const struct musaExternalMemoryMipmappedArrayDesc *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 musaExternalMemoryMipmappedArrayDesc is defined as follows:
typedef struct musaExternalMemoryMipmappedArrayDesc_st {
unsigned long long offset;
musaChannelFormatDesc formatDesc;
musaExtent extent;
unsigned int flags;
unsigned int numLevels;
} musaExternalMemoryMipmappedArrayDesc;
- where musaExternalMemoryMipmappedArrayDesc::offset is the offset in the memory object where the base level of the mipmap chain is. musaExternalMemoryMipmappedArrayDesc::formatDesc describes the format of the data. musaExternalMemoryMipmappedArrayDesc::extent specifies the dimensions of the base level of the mipmap chain. musaExternalMemoryMipmappedArrayDesc::flags are flags associated with MUSA mipmapped arrays. For further details, please refer to the documentation for musaMalloc3DArray. Note that if the mipmapped array is bound as a color target in the graphics API, then the flag musaArrayColorAttachment must be specified in musaExternalMemoryMipmappedArrayDesc::flags. musaExternalMemoryMipmappedArrayDesc::numLevels specifies the total number of levels in the mipmap chain.
- The returned MUSA mipmapped array must be freed using musaFreeMipmappedArray.
Parameters
mipmap(musaMipmappedArray_t *): Returned MUSA mipmapped arrayextMem(musaExternalMemory_t): Handle to external memory objectmipmapDesc(const struct musaExternalMemoryMipmappedArrayDesc *): MUSA array descriptor
Returns
- musaSuccess, musaErrorInvalidValue, musaErrorInvalidResourceHandle
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
- If musaExternalMemoryHandleDesc::type is musaExternalMemoryHandleTypeMtSciBuf, then musaExternalMemoryMipmappedArrayDesc::numLevels must not be greater than 1.
See also
musaDestroyExternalMemory
musaError_t musaDestroyExternalMemory(musaExternalMemory_t 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 musaFree and musaFreeMipmappedArray respectively.
Parameters
extMem(musaExternalMemory_t): External memory object to be destroyed
Returns
- musaSuccess, musaErrorInvalidResourceHandle
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
- Destroying the target object while work is still pending results in undefined behavior.
See also
- musaImportExternalMemory, musaExternalMemoryGetMappedBuffer, musaExternalMemoryGetMappedMipmappedArray
musaImportExternalSemaphore
musaError_t musaImportExternalSemaphore(musaExternalSemaphore_t *extSem_out, const struct musaExternalSemaphoreHandleDesc *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 musaExternalSemaphoreHandleDesc is defined as follows:
typedef struct musaExternalSemaphoreHandleDesc_st {
musaExternalSemaphoreHandleTypetype;
union {
int fd;
struct {
void *handle;
const void *name;
} win32;
const void *MtSciSyncObj;
} handle;
unsigned int flags;
} musaExternalSemaphoreHandleDesc;
- where musaExternalSemaphoreHandleDesc::type specifies the type of handle being imported. musaExternalSemaphoreHandleType is defined as:
typedef enum musaExternalSemaphoreHandleType_enum {
musaExternalSemaphoreHandleTypeOpaqueFd = 1,
musaExternalSemaphoreHandleTypeOpaqueWin32 = 2,
musaExternalSemaphoreHandleTypeOpaqueWin32Kmt = 3,
musaExternalSemaphoreHandleTypeD3D12Fence = 4,
musaExternalSemaphoreHandleTypeD3D11Fence = 5,
musaExternalSemaphoreHandleTypeMtSciSync = 6,
musaExternalSemaphoreHandleTypeKeyedMutex = 7,
musaExternalSemaphoreHandleTypeKeyedMutexKmt = 8,
musaExternalSemaphoreHandleTypeTimelineSemaphoreFd = 9,
musaExternalSemaphoreHandleTypeTimelineSemaphoreWin32 = 10;
} musaExternalSemaphoreHandleType;
- If musaExternalSemaphoreHandleDesc::type is musaExternalSemaphoreHandleTypeOpaqueFd, then musaExternalSemaphoreHandleDesc::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 musaExternalSemaphoreHandleDesc::type is musaExternalSemaphoreHandleTypeOpaqueWin32, then exactly one of musaExternalSemaphoreHandleDesc::handle::win32::handle and musaExternalSemaphoreHandleDesc::handle::win32::name must not be NULL. If musaExternalSemaphoreHandleDesc::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 musaExternalSemaphoreHandleDesc::handle::win32::name is not NULL, then it must name a valid synchronization object.
- If musaExternalSemaphoreHandleDesc::type is musaExternalSemaphoreHandleTypeOpaqueWin32Kmt, then musaExternalSemaphoreHandleDesc::handle::win32::handle must be non-NULL and musaExternalSemaphoreHandleDesc::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 musaExternalSemaphoreHandleDesc::type is musaExternalSemaphoreHandleTypeD3D12Fence, then exactly one of musaExternalSemaphoreHandleDesc::handle::win32::handle and musaExternalSemaphoreHandleDesc::handle::win32::name must not be NULL. If musaExternalSemaphoreHandleDesc::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 musaExternalSemaphoreHandleDesc::handle::win32::name is not NULL, then it must name a valid synchronization object that refers to a valid ID3D12Fence object.
- If musaExternalSemaphoreHandleDesc::type is musaExternalSemaphoreHandleTypeD3D11Fence, then exactly one of musaExternalSemaphoreHandleDesc::handle::win32::handle and musaExternalSemaphoreHandleDesc::handle::win32::name must not be NULL. If musaExternalSemaphoreHandleDesc::handle::win32::handle is not NULL, then it must represent a valid shared NT handle that is returned by ID3D11Fence::CreateSharedHandle. If musaExternalSemaphoreHandleDesc::handle::win32::name is not NULL, then it must name a valid synchronization object that refers to a valid ID3D11Fence object.
- If musaExternalSemaphoreHandleDesc::type is musaExternalSemaphoreHandleTypeMtSciSync, then musaExternalSemaphoreHandleDesc::handle::mtSciSyncObj represents a valid MtSciSyncObj.
- musaExternalSemaphoreHandleTypeKeyedMutex, then exactly one of musaExternalSemaphoreHandleDesc::handle::win32::handle and musaExternalSemaphoreHandleDesc::handle::win32::name must not be NULL. If musaExternalSemaphoreHandleDesc::handle::win32::handle is not NULL, then it represent a valid shared NT handle that is returned by IDXGIResource1::CreateSharedHandle when referring to a IDXGIKeyedMutex object.
- If musaExternalSemaphoreHandleDesc::type is musaExternalSemaphoreHandleTypeKeyedMutexKmt, then musaExternalSemaphoreHandleDesc::handle::win32::handle must be non-NULL and musaExternalSemaphoreHandleDesc::handle::win32::name must be NULL. The handle specified must represent a valid KMT handle that is returned by IDXGIResource::GetSharedHandle when referring to a IDXGIKeyedMutex object.
- If musaExternalSemaphoreHandleDesc::type is musaExternalSemaphoreHandleTypeTimelineSemaphoreFd, then musaExternalSemaphoreHandleDesc::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 musaExternalSemaphoreHandleDesc::type is musaExternalSemaphoreHandleTypeTimelineSemaphoreWin32, then exactly one of musaExternalSemaphoreHandleDesc::handle::win32::handle and musaExternalSemaphoreHandleDesc::handle::win32::name must not be NULL. If musaExternalSemaphoreHandleDesc::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 musaExternalSemaphoreHandleDesc::handle::win32::name is not NULL, then it must name a valid synchronization object.
Parameters
extSem_out(musaExternalSemaphore_t *): Returned handle to an external semaphoresemHandleDesc(const struct musaExternalSemaphoreHandleDesc *): Semaphore import handle descriptor
Returns
- musaSuccess, musaErrorInvalidResourceHandle, musaErrorOperatingSystem
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
See also
musaSignalExternalSemaphoresAsync
musaError_t musaSignalExternalSemaphoresAsync(const musaExternalSemaphore_t *extSemArray, const struct musaExternalSemaphoreSignalParams *paramsArray, unsigned int numExtSems, musaStream_t 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: musaExternalSemaphoreHandleTypeOpaqueFd, musaExternalSemaphoreHandleTypeOpaqueWin32, musaExternalSemaphoreHandleTypeOpaqueWin32Kmt then signaling the semaphore will set it to the signaled state.
- If the semaphore object is any one of the following types: musaExternalSemaphoreHandleTypeD3D12Fence, musaExternalSemaphoreHandleTypeD3D11Fence, musaExternalSemaphoreHandleTypeTimelineSemaphoreFd, musaExternalSemaphoreHandleTypeTimelineSemaphoreWin32 then the semaphore will be set to the value specified in musaExternalSemaphoreSignalParams::params::fence::value.
- If the semaphore object is of the type musaExternalSemaphoreHandleTypeMtSciSync this API sets musaExternalSemaphoreSignalParams::params::mtSciSync::fence to a value that can be used by subsequent waiters of the same MtSciSync object to order operations with those currently submitted in stream. Such an update will overwrite previous contents of musaExternalSemaphoreSignalParams::params::mtSciSync::fence. By default, signaling such an external semaphore object causes appropriate memory synchronization operations to be performed over all the external memory objects that are imported as musaExternalMemoryHandleTypeMtSciBuf. This ensures that any subsequent accesses made by other importers of the same set of MtSciBuf memory object(s) are coherent. These operations can be skipped by specifying the flag musaExternalSemaphoreSignalSkipMtSciBufMemSync, 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 musaExternalSemaphoreHandleTypeMtSciSync, if the MtSciSyncAttrList used to create the MtSciSyncObj had not set the flags in musaDeviceGetMtSciSyncAttributes to musaMtSciSyncAttrSignal, this API will return musaErrorNotSupported.
- musaExternalSemaphoreSignalParams::params::mtSciSync::fence associated with semaphore object of the type musaExternalSemaphoreHandleTypeMtSciSync can be deterministic. For this the MtSciSyncAttrList used to create the semaphore object must have value of MtSciSyncAttrKey_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.
- If the semaphore object is any one of the following types: musaExternalSemaphoreHandleTypeKeyedMutex, musaExternalSemaphoreHandleTypeKeyedMutexKmt, then the keyed mutex will be released with the key specified in musaExternalSemaphoreSignalParams::params::keyedmutex::key.
Parameters
extSemArray(const musaExternalSemaphore_t *): Set of external semaphores to be signaledparamsArray(const struct musaExternalSemaphoreSignalParams *): Array of semaphore parametersnumExtSems(unsigned int): Number of semaphores to signalstream(musaStream_t): Stream to enqueue the signal operations in
Returns
- musaSuccess, musaErrorInvalidResourceHandle
Note
- Additional exported symbol names in scope:
musaSignalExternalSemaphoresAsync_v2. - This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
See also
musaWaitExternalSemaphoresAsync
musaError_t musaWaitExternalSemaphoresAsync(const musaExternalSemaphore_t *extSemArray, const struct musaExternalSemaphoreWaitParams *paramsArray, unsigned int numExtSems, musaStream_t 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: musaExternalSemaphoreHandleTypeOpaqueFd, musaExternalSemaphoreHandleTypeOpaqueWin32, musaExternalSemaphoreHandleTypeOpaqueWin32Kmt 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: musaExternalSemaphoreHandleTypeD3D12Fence, musaExternalSemaphoreHandleTypeD3D11Fence, musaExternalSemaphoreHandleTypeTimelineSemaphoreFd, musaExternalSemaphoreHandleTypeTimelineSemaphoreWin32 then waiting on the semaphore will wait until the value of the semaphore is greater than or equal to musaExternalSemaphoreWaitParams::params::fence::value.
- If the semaphore object is of the type musaExternalSemaphoreHandleTypeMtSciSync then, waiting on the semaphore will wait until the musaExternalSemaphoreSignalParams::params::mtSciSync::fence is signaled by the signaler of the MtSciSyncObj 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 musaExternalMemoryHandleTypeMtSciBuf. This ensures that any subsequent accesses made by other importers of the same set of MtSciBuf memory object(s) are coherent. These operations can be skipped by specifying the flag musaExternalSemaphoreWaitSkipMtSciBufMemSync, 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 musaExternalSemaphoreHandleTypeMtSciSync, if the MtSciSyncAttrList used to create the MtSciSyncObj had not set the flags in musaDeviceGetMtSciSyncAttributes to musaMtSciSyncAttrWait, this API will return musaErrorNotSupported.
- If the semaphore object is any one of the following types: musaExternalSemaphoreHandleTypeKeyedMutex, musaExternalSemaphoreHandleTypeKeyedMutexKmt, then the keyed mutex will be acquired when it is released with the key specified in musaExternalSemaphoreSignalParams::params::keyedmutex::key or until the timeout specified by musaExternalSemaphoreSignalParams::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 musaExternalSemaphore_t *): External semaphores to be waited onparamsArray(const struct musaExternalSemaphoreWaitParams *): Array of semaphore parametersnumExtSems(unsigned int): Number of semaphores to wait onstream(musaStream_t): Stream to enqueue the wait operations in
Returns
- musaSuccess, musaErrorInvalidResourceHandle musaErrorTimeout
Note
- Additional exported symbol names in scope:
musaWaitExternalSemaphoresAsync_v2. - This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
See also
musaDestroyExternalSemaphore
musaError_t musaDestroyExternalSemaphore(musaExternalSemaphore_t 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(musaExternalSemaphore_t): External semaphore to be destroyed
Returns
- musaSuccess, musaErrorInvalidResourceHandle
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
- Destroying the target object while work is still pending results in undefined behavior.
See also
3.9 Execution Control
musaLaunchKernel
musaError_t musaLaunchKernel(const void *func, dim3 gridDim, dim3 blockDim, void **args, size_t sharedMem, musaStream_t stream)
Description
- Launches a device function.
- The function invokes kernel func on gridDim (gridDim.x gridDim.y gridDim.z) grid of blocks. Each block contains blockDim (blockDim.x blockDim.y blockDim.z) threads.
- If the kernel has N parameters the args should point to array of N pointers. Each pointer, from args[0] to args[N - 1], point to the region of memory from which the actual parameter will be copied.
- For templated functions, pass the function symbol as follows:
func_name<template_arg_0,...,template_arg_N> - sharedMem sets the amount of dynamic shared memory that will be available to each thread block.
- stream specifies a stream the invocation is associated to.
Parameters
func(const void *): Device function symbolgridDim(dim3): Grid dimentionsblockDim(dim3): Block dimentionsargs(void **): ArgumentssharedMem(size_t): Shared memorystream(musaStream_t): Stream identifier
Returns
- musaSuccess, musaErrorInvalidDeviceFunction, musaErrorInvalidConfiguration, musaErrorLaunchFailure, musaErrorLaunchTimeout, musaErrorLaunchOutOfResources, musaErrorSharedObjectInitFailed, musaErrorInvalidPtx, musaErrorUnsupportedPtxVersion, musaErrorNoKernelImageForDevice, musaErrorJitCompilerNotFound, musaErrorJitCompilationDisabled
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
- See the default-stream note for NULL stream semantics.
- This API operates on a musaKernel_t handle.
See also
- musaLaunchKernel (C++ API), muLaunchKernel
musaLaunchKernelExC
musaError_t musaLaunchKernelExC(const musaLaunchConfig_t *config, const void *func, void **args)
Description
- Launches a MUSA function with launch-time configuration.
- Note that the functionally equivalent variadic template musaLaunchKernelEx is available for C++11 and newer.
- Invokes the kernel func on config->gridDim (config->gridDim.x config->gridDim.y config->gridDim.z) grid of blocks. Each block contains config->blockDim (config->blockDim.x config->blockDim.y config->blockDim.z) threads.
- config->dynamicSmemBytes sets the amount of dynamic shared memory that will be available to each thread block.
- config->stream specifies a stream the invocation is associated to.
- Configuration beyond grid and block dimensions, dynamic shared memory size, and stream can be provided with the following two fields of config:
- config->attrs is an array of config->numAttrs contiguous musaLaunchAttribute elements. The value of this pointer is not considered if config->numAttrs is zero. However, in that case, it is recommended to set the pointer to NULL. config->numAttrs is the number of attributes populating the first config->numAttrs positions of the config->attrs array.
- If the kernel has N parameters the args should point to array of N pointers. Each pointer, from args[0] to args[N - 1], point to the region of memory from which the actual parameter will be copied.
- N.B. This function is so named to avoid unintentionally invoking the templated version, musaLaunchKernelEx, for kernels taking a single void** or void* parameter.
Parameters
config(const musaLaunchConfig_t *): Launch configurationfunc(const void *): Kernel to launchargs(void **): Array of pointers to kernel parameters
Returns
- musaSuccess, musaErrorInvalidDeviceFunction, musaErrorInvalidConfiguration, musaErrorLaunchFailure, musaErrorLaunchTimeout, musaErrorLaunchOutOfResources, musaErrorSharedObjectInitFailed, musaErrorInvalidPtx, musaErrorUnsupportedPtxVersion, musaErrorNoKernelImageForDevice, musaErrorJitCompilerNotFound, musaErrorJitCompilationDisabled
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
- See the default-stream note for NULL stream semantics.
- This API operates on a musaKernel_t handle.
See also
- musaLaunchKernelEx(const musaLaunchConfig_t *config, void (*kernel)(ExpTypes...), ActTypes &&... args) "musaLaunchKernelEx (C++ API)", muLaunchKernelEx
musaLaunchCooperativeKernel
musaError_t musaLaunchCooperativeKernel(const void *func, dim3 gridDim, dim3 blockDim, void **args, size_t sharedMem, musaStream_t stream)
Description
- Launches a device function where thread blocks can cooperate and synchronize as they execute.
- The function invokes kernel func on gridDim (gridDim.x gridDim.y gridDim.z) grid of blocks. Each block contains blockDim (blockDim.x blockDim.y blockDim.z) threads.
- The device on which this kernel is invoked must have a non-zero value for the device attribute musaDevAttrCooperativeLaunch.
- The total number of blocks launched cannot exceed the maximum number of blocks per multiprocessor as returned by musaOccupancyMaxActiveBlocksPerMultiprocessor (or musaOccupancyMaxActiveBlocksPerMultiprocessorWithFlags) times the number of multiprocessors as specified by the device attribute musaDevAttrMultiProcessorCount.
- The kernel cannot make use of MUSA dynamic parallelism.
- If the kernel has N parameters the args should point to array of N pointers. Each pointer, from args[0] to args[N - 1], point to the region of memory from which the actual parameter will be copied.
- For templated functions, pass the function symbol as follows:
func_name<template_arg_0,...,template_arg_N> - sharedMem sets the amount of dynamic shared memory that will be available to each thread block.
- stream specifies a stream the invocation is associated to.
Parameters
func(const void *): Device function symbolgridDim(dim3): Grid dimentionsblockDim(dim3): Block dimentionsargs(void **): ArgumentssharedMem(size_t): Shared memorystream(musaStream_t): Stream identifier
Returns
- musaSuccess, musaErrorInvalidDeviceFunction, musaErrorInvalidConfiguration, musaErrorLaunchFailure, musaErrorLaunchTimeout, musaErrorLaunchOutOfResources, musaErrorCooperativeLaunchTooLarge, musaErrorSharedObjectInitFailed
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
- See the default-stream note for NULL stream semantics.
- This API operates on a musaKernel_t handle.
See also
- musaLaunchCooperativeKernel (C++ API), musaLaunchCooperativeKernelMultiDevice, muLaunchCooperativeKernel
musaLaunchCooperativeKernelMultiDevice
musaError_t musaLaunchCooperativeKernelMultiDevice(struct musaLaunchParams *launchParamsList, unsigned int numDevices, unsigned int flags)
Description
- Launches device functions on multiple devices where thread blocks can cooperate and synchronize as they execute.
- DeprecatedThis function is deprecated as of MUSA 11.3.
- Invokes kernels as specified in the launchParamsList array where each element of the array specifies all the parameters required to perform a single kernel launch. These kernels can cooperate and synchronize as they execute. The size of the array is specified by numDevices.
- No two kernels can be launched on the same device. All the devices targeted by this multi-device launch must be identical. All devices must have a non-zero value for the device attribute musaDevAttrCooperativeMultiDeviceLaunch.
- The same kernel must be launched on all devices. Note that any device or constant variables are independently instantiated on every device. It is the application's responsiblity to ensure these variables are initialized and used appropriately.
- The size of the grids as specified in blocks, the size of the blocks themselves and the amount of shared memory used by each thread block must also match across all launched kernels.
- The streams used to launch these kernels must have been created via either musaStreamCreate or musaStreamCreateWithPriority or musaStreamCreateWithPriority. The NULL stream or musaStreamLegacy or musaStreamPerThread cannot be used.
- The total number of blocks launched per kernel cannot exceed the maximum number of blocks per multiprocessor as returned by musaOccupancyMaxActiveBlocksPerMultiprocessor (or musaOccupancyMaxActiveBlocksPerMultiprocessorWithFlags) times the number of multiprocessors as specified by the device attribute musaDevAttrMultiProcessorCount. Since the total number of blocks launched per device has to match across all devices, the maximum number of blocks that can be launched per device will be limited by the device with the least number of multiprocessors.
- The kernel cannot make use of MUSA dynamic parallelism.
- The musaLaunchParams structure is defined as:
struct musaLaunchParams {
void *func;
dim3 gridDim;
dim3 blockDim;
void **args;
size_t sharedMem;
musaStream_t stream;
};
- ; where: musaLaunchParams::func specifies the kernel to be launched. This same functions must be launched on all devices. For templated functions, pass the function symbol as follows:
func_name<template_arg_0,...,template_arg_N>musaLaunchParams::gridDim specifies the width, height and depth of the grid in blocks. This must match across all kernels launched. musaLaunchParams::blockDim is the width, height and depth of each thread block. This must match across all kernels launched. musaLaunchParams::args specifies the arguments to the kernel. If the kernel has N parameters then musaLaunchParams::args should point to array of N pointers. Each pointer, from musaLaunchParams::args[0] to musaLaunchParams::args[N - 1], point to the region of memory from which the actual parameter will be copied. musaLaunchParams::sharedMem is the dynamic shared-memory size per thread block in bytes. This must match across all kernels launched. musaLaunchParams::stream is the handle to the stream to perform the launch in. This cannot be the NULL stream or musaStreamLegacy or musaStreamPerThread. - By default, the kernel won't begin execution on any GPU until all prior work in all the specified streams has completed. This behavior can be overridden by specifying the flag musaCooperativeLaunchMultiDeviceNoPreSync. When this flag is specified, each kernel will only wait for prior work in the stream corresponding to that GPU to complete before it begins execution.
- Similarly, by default, any subsequent work pushed in any of the specified streams will not begin execution until the kernels on all GPUs have completed. This behavior can be overridden by specifying the flag musaCooperativeLaunchMultiDeviceNoPostSync. When this flag is specified, any subsequent work pushed in any of the specified streams will only wait for the kernel launched on the GPU corresponding to that stream to complete before it begins execution.
Parameters
launchParamsList(struct musaLaunchParams *): List of launch parameters, one per devicenumDevices(unsigned int): Size of the launchParamsList arrayflags(unsigned int): Flags to control launch behavior
Returns
- musaSuccess, musaErrorInvalidDeviceFunction, musaErrorInvalidConfiguration, musaErrorLaunchFailure, musaErrorLaunchTimeout, musaErrorLaunchOutOfResources, musaErrorCooperativeLaunchTooLarge, musaErrorSharedObjectInitFailed
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
- See the default-stream note for NULL stream semantics.
See also
- musaLaunchCooperativeKernel (C++ API), musaLaunchCooperativeKernel, muLaunchCooperativeKernelMultiDevice
musaFuncSetCacheConfig
musaError_t musaFuncSetCacheConfig(const void *func, enum musaFuncCache cacheConfig)
Description
- Sets the preferred cache configuration for a device function.
- On devices where the L1 cache and shared memory use the same hardware resources, this sets through cacheConfig the preferred cache configuration for the function specified via func. This is only a preference. The runtime will use the requested configuration if possible, but it is free to choose a different configuration if required to execute func.
- func is a device function symbol and must be declared as a global function. If the specified function does not exist, then musaErrorInvalidDeviceFunction is returned. For templated functions, pass the function symbol as follows:
func_name<template_arg_0,...,template_arg_N> - 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: musaFuncCachePreferNone: no preference for shared memory or L1 (default) musaFuncCachePreferShared: prefer larger shared memory and smaller L1 cache musaFuncCachePreferL1: prefer larger L1 cache and smaller shared memory musaFuncCachePreferEqual: prefer equal size L1 cache and shared memory
Parameters
func(const void *): Device function symbolcacheConfig(enum musaFuncCache): Requested cache configuration
Returns
- musaSuccess, musaErrorInvalidDeviceFunction
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
- This string-based API is deprecated; use the newer typed API instead.
- This API does not accept a musaKernel_t casted as void*. If cache config modification is required for a musaKernel_t (or a global function), it can be replaced with a call to musaFuncSetAttributes with the attribute musaFuncAttributePreferredSharedMemoryCarveout to specify a more granular L1 cache and shared memory split configuration.
See also
- musaFuncSetCacheConfig (C++ API), musaFuncGetAttributes (C API), musaLaunchKernel (C API), muFuncSetCacheConfig
musaFuncGetAttributes
musaError_t musaFuncGetAttributes(struct musaFuncAttributes *attr, const void *func)
Description
- Find out attributes for a given function.
- This function obtains the attributes of a function specified via func. func is a device function symbol and must be declared as a global function. The fetched attributes are placed in attr. If the specified function does not exist, then it is assumed to be a musaKernel_t and used as is. For templated functions, pass the function symbol as follows:
func_name<template_arg_0,...,template_arg_N> - Note that some function attributes such as maxThreadsPerBlock may vary based on the device that is currently being used.
Parameters
attr(struct musaFuncAttributes *): Return pointer to function's attributesfunc(const void *): Device function symbol
Returns
- musaSuccess, musaErrorInvalidDeviceFunction
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
- This string-based API is deprecated; use the newer typed API instead.
- This API operates on a musaKernel_t handle.
See also
- musaFuncSetCacheConfig (C API), musaFuncGetAttributes (C++ API), musaLaunchKernel (C API), muFuncGetAttribute
musaFuncSetAttribute
musaError_t musaFuncSetAttribute(const void *func, enum musaFuncAttribute attr, int value)
Description
- Set attributes for a given function.
- This function sets the attributes of a function specified via func. The parameter func must be a pointer to a function that executes on the device. The parameter specified by func must be declared as a global function. The enumeration defined by attr is set to the value defined by value. If the specified function does not exist, then it is assumed to be a musaKernel_t and used as is. If the specified attribute cannot be written, or if the value is incorrect, then musaErrorInvalidValue is returned.
- Valid values for attr are: musaFuncAttributeMaxDynamicSharedMemorySize - The requested maximum size in bytes of dynamically-allocated shared memory. The sum of this value and the function attribute sharedSizeBytes cannot exceed the device attribute musaDevAttrMaxSharedMemoryPerBlockOptin. The maximal size of requestable dynamic shared memory may differ by GPU architecture. musaFuncAttributePreferredSharedMemoryCarveout - 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 musaDevAttrMaxSharedMemoryPerMultiprocessor. This is only a hint, and the driver can choose a different ratio if required to execute the function. musaFuncAttributeRequiredClusterWidth: 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 musaErrorNotPermitted. musaFuncAttributeRequiredClusterHeight: 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 musaErrorNotPermitted. musaFuncAttributeRequiredClusterDepth: 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 musaErrorNotPermitted. musaFuncAttributeNonPortableClusterSizeAllowed: Indicates whether the function can be launched with non-portable cluster size. 1 is allowed, 0 is disallowed. musaFuncAttributeClusterSchedulingPolicyPreference: The block scheduling policy of a function. The value type is musaClusterSchedulingPolicy.
Parameters
func(const void *): Function to get attributes ofattr(enum musaFuncAttribute): Attribute to setvalue(int): Value to set
Returns
- musaSuccess, musaErrorInvalidDeviceFunction, musaErrorInvalidValue
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
- This API operates on a musaKernel_t handle.
musaFuncGetName
musaError_t musaFuncGetName(const char **name, const void *func)
Description
- Returns the function name for a device entry function pointer.
- Returns in **name the function name associated with the symbol func . The function name is returned as a null-terminated string. This API may return a mangled name if the function is not declared as having C linkage. If **name is NULL, musaErrorInvalidValue is returned. If func is not a device entry function, then it is assumed to be a musaKernel_t and used as is.
Parameters
name(const char **): The returned name of the functionfunc(const void *): The function pointer to retrieve name for
Returns
- musaSuccess, musaErrorInvalidValue, musaErrorInvalidDeviceFunction
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
- This API operates on a musaKernel_t handle.
musaFuncGetParamCount
musaError_t musaFuncGetParamCount(const void *func, size_t *paramCount)
Description
- Returns the number of parameters used by the function.
- Queries the number of kernel parameters used by func and returns it in paramCount
Parameters
func(const void *): The function to queryparamCount(size_t *): Returns the number of parameters used by the function
Returns
- MUSA_SUCCESS, MUSA_ERROR_INVALID_VALUE
Note
- Experimental in the current MUSA SDK 5.2.0 delivery scope.
musaFuncGetParamInfo
musaError_t musaFuncGetParamInfo(const void *func, 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 in func's list of parameters and returns parameter information via paramOffset and paramSize. paramOffset returns the offset of the parameter in the device-side parameter layout. paramSize returns the size in bytes of the parameter. 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 func takes.
Parameters
func(const void *): The function to queryparamIndex(size_t): The parameter index to queryparamOffset(size_t *): The offset into the device-side parameter layout at which the parameter residesparamSize(size_t *): 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.
- This API operates on a musaKernel_t handle.
musaLaunchHostFunc
musaError_t musaLaunchHostFunc(musaStream_t stream, musaHostFn_t fn, void *userData)
Description
- Converts a double argument to be executed on a device.
- Converts the double value of d to an internal float representation if the device does not support double arithmetic. If the device does natively support doubles, then this function does nothing.
- DeprecatedThis function is deprecated as of MUSA 7.5
- Converts the double value of d from a potentially internal float representation if the device does not support double arithmetic. If the device does natively support doubles, then this function does nothing.
- Enqueues a host function to run in a stream. The function will be called after currently enqueued work and will block work added after it.
- The host function must not make any MUSA API calls. Attempting to use a MUSA API may result in musaErrorNotPermitted, but this is not required. The host function must not perform any synchronization that may depend on outstanding MUSA work not mandated to run earlier. Host functions without a mandated order (such as in independent streams) execute in undefined order and may be serialized.
- For the purposes of Unified Memory, execution makes a number of guarantees: The stream is considered idle for the duration of the function's execution. Thus, for example, the function may always use memory attached to the stream it was enqueued in. The start of execution of the function has the same effect as synchronizing an event recorded in the same stream immediately prior to the function. It thus synchronizes streams which have been "joined" prior to the function. 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 function might use global attached memory even if work has been added to another stream, if the work has been ordered behind the function call with an event. Completion of the function does not cause a stream to become active except as described above. The stream will remain idle if no device work follows the function, and will remain idle across consecutive host functions or stream callbacks without device work in between. Thus, for example, stream synchronization can be done by signaling from a host function at the end of the stream.
- Note that, in constrast to muStreamAddCallback, the function will not be called in the event of an error in the MUSA context.
Parameters
stream(musaStream_t)fn(musaHostFn_t): The function to call once preceding stream operations are completeuserData(void *): User-specified data to be passed to the function
Returns
- musaSuccess
- musaSuccess, musaErrorInvalidResourceHandle, musaErrorInvalidValue, musaErrorNotSupported
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
- See the default-stream note for NULL stream semantics.
See also
- musaFuncSetCacheConfig (C API), musaFuncGetAttributes (C API), musaSetDoubleForHost
- musaFuncSetCacheConfig (C API), musaFuncGetAttributes (C API), musaSetDoubleForDevice
- musaStreamCreate, musaStreamQuery, musaStreamSynchronize, musaStreamWaitEvent, musaStreamDestroy, musaMallocManaged, musaStreamAttachMemAsync, musaStreamAddCallback, muLaunchHostFunc
3.10 Execution Control [DEPRECATED]
musaFuncSetSharedMemConfig
musaError_t musaFuncSetSharedMemConfig(const void *func, enum musaSharedMemConfig config)
Description
- Sets the shared memory configuration for a device function.
- Deprecated
- On devices with configurable shared memory banks, this function will force all subsequent launches of the specified device function to have the given shared memory bank size configuration. On any given launch of the function, the shared memory configuration of the device will be temporarily changed if needed to suit the function's preferred configuration. Changes in shared memory configuration between subsequent launches of functions, may introduce a device side synchronization point.
- Any per-function setting of shared memory bank size set via musaFuncSetSharedMemConfig will override the device wide setting set by musaDeviceSetSharedMemConfig.
- 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.
- For templated functions, pass the function symbol as follows:
func_name<template_arg_0,...,template_arg_N> - The supported bank configurations are: musaSharedMemBankSizeDefault: use the device's shared memory configuration when launching this function. musaSharedMemBankSizeFourByte: set shared memory bank width to be four bytes natively when launching this function. musaSharedMemBankSizeEightByte: set shared memory bank width to be eight bytes natively when launching this function.
Parameters
func(const void *): Device function symbolconfig(enum musaSharedMemConfig): Requested shared memory configuration
Returns
- musaSuccess, musaErrorInvalidDeviceFunction, musaErrorInvalidValue
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
- This string-based API is deprecated; use the newer typed API instead.
See also
- musaDeviceSetSharedMemConfig, musaDeviceGetSharedMemConfig, musaDeviceSetCacheConfig, musaDeviceGetCacheConfig, musaFuncSetCacheConfig, muFuncSetSharedMemConfig
3.11 Occupancy
musaOccupancyMaxActiveBlocksPerMultiprocessorWithFlags
musaError_t musaOccupancyMaxActiveBlocksPerMultiprocessorWithFlags(int *numBlocks, const void *func, int blockSize, size_t dynamicSMemSize, unsigned int flags)
Description
- Returns occupancy for a device function with the specified flags.
- Returns in *numBlocks the maximum number of active blocks per streaming multiprocessor for the device function.
- The flags parameter controls how special cases are handled. Valid flags include:
- musaOccupancyDefault: keeps the default behavior as musaOccupancyMaxActiveBlocksPerMultiprocessor musaOccupancyDisableCachingOverride: This flag suppresses the default behavior on platform where global caching affects occupancy. On such platforms, if caching is enabled, but per-block SM resource usage would result in zero occupancy, the occupancy calculator will calculate the occupancy as if caching is disabled. Setting this flag makes the occupancy calculator to return 0 in such cases. More information can be found about this feature in the "Unified L1/Texture Cache" section of the Maxwell tuning guide.
Parameters
numBlocks(int *): Returned occupancyfunc(const void *): Kernel function for which occupancy is calculatedblockSize(int): Block size the kernel is intended to be launched withdynamicSMemSize(size_t): Per-block dynamic shared memory usage intended, in bytesflags(unsigned int): Requested behavior for the occupancy calculator
Returns
- musaSuccess, musaErrorInvalidDevice, musaErrorInvalidDeviceFunction, musaErrorInvalidValue, musaErrorUnknown
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
- This API operates on a musaKernel_t handle.
See also
- musaOccupancyMaxActiveBlocksPerMultiprocessor, musaOccupancyMaxPotentialBlockSize (C++ API), musaOccupancyMaxPotentialBlockSizeWithFlags (C++ API), musaOccupancyMaxPotentialBlockSizeVariableSMem (C++ API), musaOccupancyMaxPotentialBlockSizeVariableSMemWithFlags (C++ API), musaOccupancyAvailableDynamicSMemPerBlock (C++ API), muOccupancyMaxActiveBlocksPerMultiprocessorWithFlags
3.12 Memory Management
musaMallocManaged
musaError_t musaMallocManaged(void **devPtr, size_t size, unsigned int flags)
Description
- Allocates memory that will be automatically managed by the Unified Memory system.
- Allocates size bytes of managed memory on the device and returns in *devPtr a pointer to the allocated memory. If the device doesn't support allocating managed memory, musaErrorNotSupported is returned. Support for managed memory can be queried using the device attribute musaDevAttrManagedMemory. The allocated memory is suitably aligned for any kind of variable. The memory is not cleared. If size is 0, musaMallocManaged returns musaErrorInvalidValue. 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 musaMemAttachGlobal or musaMemAttachHost. The default value for flags is musaMemAttachGlobal. If musaMemAttachGlobal is specified, then this memory is accessible from any stream on any device. If musaMemAttachHost is specified, then the allocation should not be accessed from devices that have a zero value for the device attribute musaDevAttrConcurrentManagedAccess; an explicit call to musaStreamAttachMemAsync will be required to enable access on such devices.
- If the association is later changed via musaStreamAttachMemAsync to a single stream, the default association, as specifed during musaMallocManaged, is restored when that stream is destroyed. For managed variables, the default association is always musaMemAttachGlobal. 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 musaMallocManaged should be released with musaFree.
- Device memory oversubscription is possible for GPUs that have a non-zero value for the device attribute musaDevAttrConcurrentManagedAccess. 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 musaDevAttrConcurrentManagedAccess, 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 musaMemAdvise. The application can also explicitly migrate memory to a desired processor's memory via musaMemPrefetchAsync.
- In a multi-GPU system where all of the GPUs have a zero value for the device attribute musaDevAttrConcurrentManagedAccess 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 musaMallocManaged 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 musaDevAttrConcurrentManagedAccess 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 musaDevAttrConcurrentManagedAccess. 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 devices used in that process that support managed memory have to be peer-to-peer compatible with each other. The error musaErrorInvalidDevice will be returned if a device that supports managed memory is used and it is not peer-to-peer compatible with any of the other managed memory supporting devices that were previously used in that process, even if musaDeviceReset has been called on those devices. These environment variables are described in the MUSA programming guide under the "MUSA environment variables" section.
Parameters
devPtr(void **): Pointer to allocated device memorysize(size_t): Requested allocation size in bytesflags(unsigned int): Must be either musaMemAttachGlobal or musaMemAttachHost (defaults to musaMemAttachGlobal)
Returns
- musaSuccess, musaErrorMemoryAllocation, musaErrorNotSupported, musaErrorInvalidValue
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
See also
- musaMallocPitch, musaFree, musaMallocArray, musaFreeArray, musaMalloc3D, musaMalloc3DArray, musaMallocHost (C API), musaFreeHost, musaHostAlloc, musaDeviceGetAttribute, musaStreamAttachMemAsync, muMemAllocManaged
musaMalloc
musaError_t musaMalloc(void **devPtr, size_t size)
Description
- Allocate memory on the device.
- Allocates size bytes of linear memory on the device and returns in *devPtr a pointer to the allocated memory. The allocated memory is suitably aligned for any kind of variable. The memory is not cleared. musaMalloc() returns musaErrorMemoryAllocation in case of failure.
- The device version of musaFree cannot be used with a *devPtr allocated using the host API, and vice versa.
Parameters
devPtr(void **): Pointer to allocated device memorysize(size_t): Requested allocation size in bytes
Returns
- musaSuccess, musaErrorInvalidValue, musaErrorMemoryAllocation
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
See also
- musaMallocPitch, musaFree, musaMallocArray, musaFreeArray, musaMalloc3D, musaMalloc3DArray, musaMallocHost (C API), musaFreeHost, musaHostAlloc, muMemAlloc
musaMallocHost
musaError_t musaMallocHost(void **ptr, size_t size)
Description
- Allocates page-locked memory on the host.
- Allocates size 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 musaMemcpy*(). 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 pageableMemoryAccessUsesHostPageTables is true, musaMallocHost may not page-lock the allocated memory.
- Page-locking excessive amounts of memory with musaMallocHost() 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.
Parameters
ptr(void **): Pointer to allocated host memorysize(size_t): Requested allocation size in bytes
Returns
- musaSuccess, musaErrorInvalidValue, musaErrorMemoryAllocation
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
See also
- musaMalloc, musaMallocPitch, musaMallocArray, musaMalloc3D, musaMalloc3DArray, musaHostAlloc, musaFree, musaFreeArray, musaMallocHost (C++ API), musaFreeHost, musaHostAlloc, muMemAllocHost
musaMallocPitch
musaError_t musaMallocPitch(void **devPtr, size_t *pitch, size_t width, size_t height)
Description
- Allocates pitched memory on the device.
- Allocates at least width (in bytes) * height bytes of linear memory on the device and returns in devPtr 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. The pitch returned in pitch by musaMallocPitch() 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;
- For allocations of 2D arrays, it is recommended that programmers consider performing pitch allocations using musaMallocPitch(). Due to pitch 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).
Parameters
devPtr(void **): Pointer to allocated pitched device memorypitch(size_t *): Pitch for allocationwidth(size_t): Requested pitched allocation width (in bytes)height(size_t): Requested pitched allocation height
Returns
- musaSuccess, musaErrorInvalidValue, musaErrorMemoryAllocation
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
See also
- musaMalloc, musaFree, musaMallocArray, musaFreeArray, musaMallocHost (C API), musaFreeHost, musaMalloc3D, musaMalloc3DArray, musaHostAlloc, muMemAllocPitch
musaMallocArray
musaError_t musaMallocArray(musaArray_t *array, const struct musaChannelFormatDesc *desc, size_t width, size_t height, unsigned int flags)
Description
- Allocate an array on the device.
- Allocates a MUSA array according to the musaChannelFormatDesc structure desc and returns a handle to the new MUSA array in *array.
- The musaChannelFormatDesc is defined as:
struct musaChannelFormatDesc {
int x, y, z, w;
enum musaChannelFormatKind f;
};
- ; where musaChannelFormatKind is one of musaChannelFormatKindSigned, musaChannelFormatKindUnsigned, or musaChannelFormatKindFloat.
- The flags parameter enables different options to be specified that affect the allocation, as follows. musaArrayDefault: This flag's value is defined to be 0 and provides default array allocation musaArraySurfaceLoadStore: Allocates an array that can be read from or written to using a surface reference musaArrayTextureGather: This flag indicates that texture gather operations will be performed on the array. musaArraySparse: Allocates a MUSA array without physical backing memory. The subregions within this sparse array can later be mapped onto a physical memory allocation by calling muMemMapArrayAsync. The physical backing memory must be allocated via muMemCreate. musaArrayDeferredMapping: Allocates a MUSA array without physical backing memory. The entire array can later be mapped onto a physical memory allocation by calling muMemMapArrayAsync. The physical backing memory must be allocated via muMemCreate.
- width and height must meet certain size requirements. See musaMalloc3DArray() for more details.
Parameters
array(musaArray_t *): Pointer to allocated array in device memorydesc(const struct musaChannelFormatDesc *): Requested channel formatwidth(size_t): Requested array allocation widthheight(size_t): Requested array allocation heightflags(unsigned int): Requested properties of allocated array
Returns
- musaSuccess, musaErrorInvalidValue, musaErrorMemoryAllocation
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
See also
- musaMalloc, musaMallocPitch, musaFree, musaFreeArray, musaMallocHost (C API), musaFreeHost, musaMalloc3D, musaMalloc3DArray, musaHostAlloc, muArrayCreate
musaFree
musaError_t musaFree(void *devPtr)
Description
- Frees memory on the device.
- Frees the memory space pointed to by devPtr, which must have been returned by a previous call to one of the following memory allocation APIs - musaMalloc(), musaMallocPitch(), musaMallocManaged(), musaMallocAsync(), musaMallocFromPoolAsync().
- Note - This API will not perform any implicit synchronization when the pointer was allocated with musaMallocAsync or musaMallocFromPoolAsync. Callers must ensure that all accesses to these pointer have completed before invoking musaFree. For best performance and memory reuse, users should use musaFreeAsync to free memory allocated via the stream ordered memory allocator. For all other pointers, this API may perform implicit synchronization.
- If musaFree(devPtr) has already been called before, an error is returned. If devPtr is 0, no operation is performed. musaFree() returns musaErrorValue in case of failure.
- The device version of musaFree cannot be used with a *devPtr allocated using the host API, and vice versa.
Parameters
devPtr(void *): Device pointer to memory to free
Returns
- musaSuccess, musaErrorInvalidValue
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
See also
- musaMalloc, musaMallocPitch, musaMallocManaged, musaMallocArray, musaFreeArray, musaMallocAsync, musaMallocFromPoolAsync musaMallocHost (C API), musaFreeHost, musaMalloc3D, musaMalloc3DArray, musaFreeAsync musaHostAlloc, muMemFree
musaFreeHost
musaError_t musaFreeHost(void *ptr)
Description
- Frees page-locked memory.
- Frees the memory space pointed to by hostPtr, which must have been returned by a previous call to musaMallocHost() or musaHostAlloc().
Parameters
ptr(void *): Pointer to memory to free
Returns
- musaSuccess, musaErrorInvalidValue
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
See also
- musaMalloc, musaMallocPitch, musaFree, musaMallocArray, musaFreeArray, musaMallocHost (C API), musaMalloc3D, musaMalloc3DArray, musaHostAlloc, muMemFreeHost
musaFreeArray
musaError_t musaFreeArray(musaArray_t array)
Description
- Frees an array on the device.
- Frees the MUSA array array, which must have been returned by a previous call to musaMallocArray(). If devPtr is 0, no operation is performed.
Parameters
array(musaArray_t): Pointer to array to free
Returns
- musaSuccess, musaErrorInvalidValue
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
See also
- musaMalloc, musaMallocPitch, musaFree, musaMallocArray, musaMallocHost (C API), musaFreeHost, musaHostAlloc, muArrayDestroy
musaFreeMipmappedArray
musaError_t musaFreeMipmappedArray(musaMipmappedArray_t mipmappedArray)
Description
- Frees a mipmapped array on the device.
- Frees the MUSA mipmapped array mipmappedArray, which must have been returned by a previous call to musaMallocMipmappedArray(). If devPtr is 0, no operation is performed.
Parameters
mipmappedArray(musaMipmappedArray_t): Pointer to mipmapped array to free
Returns
- musaSuccess, musaErrorInvalidValue
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
See also
- musaMalloc, musaMallocPitch, musaFree, musaMallocArray, musaMallocHost (C API), musaFreeHost, musaHostAlloc, muMipmappedArrayDestroy
musaHostAlloc
musaError_t musaHostAlloc(void **pHost, size_t size, unsigned int flags)
Description
- Allocates page-locked memory on the host.
- Allocates size 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 musaMemcpy(). 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(). Allocating excessive amounts of pinned 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. musaHostAllocDefault: This flag's value is defined to be 0 and causes musaHostAlloc() to emulate musaMallocHost(). musaHostAllocPortable: The memory returned by this call will be considered as pinned memory by all MUSA contexts, not just the one that performed the allocation. musaHostAllocMapped: Maps the allocation into the MUSA address space. The device pointer to the memory may be obtained by calling musaHostGetDevicePointer(). musaHostAllocWriteCombined: 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 device 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.
- In order for the musaHostAllocMapped flag to have any effect, the MUSA context must support the musaDeviceMapHost flag, which can be checked via musaGetDeviceFlags(). The musaDeviceMapHost flag is implicitly set for contexts created via the runtime API.
- The musaHostAllocMapped flag may be specified on MUSA contexts for devices that do not support mapped pinned memory. The failure is deferred to musaHostGetDevicePointer() because the memory may be mapped into other MUSA contexts via the musaHostAllocPortable flag.
- Memory allocated by this function must be freed with musaFreeHost().
Parameters
pHost(void **): Device pointer to allocated memorysize(size_t): Requested allocation size in bytesflags(unsigned int): Requested properties of allocated memory
Returns
- musaSuccess, musaErrorInvalidValue, musaErrorMemoryAllocation
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
See also
musaHostRegister
musaError_t musaHostRegister(void *ptr, size_t size, unsigned int flags)
Description
- Registers an existing host memory range for use by MUSA.
- Page-locks the memory range specified by ptr and size and maps it for the device(s) as specified by flags. This memory range also is added to the same tracking mechanism as musaHostAlloc() to automatically accelerate calls to functions such as musaMemcpy(). 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 pageableMemoryAccessUsesHostPageTables is true, musaHostRegister will not page-lock the memory range specified by ptr but only populate unpopulated pages.
- musaHostRegister is supported only on I/O coherent devices that have a non-zero value for the device attribute musaDevAttrHostRegisterSupported.
- The flags parameter enables different options to be specified that affect the allocation, as follows.
- musaHostRegisterDefault: On a system with unified virtual addressing, the memory will be both mapped and portable. On a system with no unified virtual addressing, the memory will be neither mapped nor portable. musaHostRegisterPortable: The memory returned by this call will be considered as pinned memory by all MUSA contexts, not just the one that performed the allocation. musaHostRegisterMapped: Maps the allocation into the MUSA address space. The device pointer to the memory may be obtained by calling musaHostGetDevicePointer(). musaHostRegisterIoMemory: The passed memory pointer is treated as pointing to some memory-mapped I/O space, e.g. belonging to a third-party PCIe device, and it will marked as non cache-coherent and contiguous. musaHostRegisterReadOnly: The passed memory pointer is treated as pointing to memory that is considered read-only by the device. On platforms without musaDevAttrPageableMemoryAccessUsesHostPageTables, 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 musaDevAttrHostRegisterReadOnlySupported. Using this flag with a current context associated with a device that does not have this attribute set will cause musaHostRegister to error with musaErrorNotSupported.
- All of these flags are orthogonal to one another: a developer may page-lock memory that is portable or mapped with no restrictions.
- The MUSA context must have been created with the musaMapHost flag in order for the musaHostRegisterMapped flag to have any effect.
- The musaHostRegisterMapped flag may be specified on MUSA contexts for devices that do not support mapped pinned memory. The failure is deferred to musaHostGetDevicePointer() because the memory may be mapped into other MUSA contexts via the musaHostRegisterPortable flag.
- For devices that have a non-zero value for the device attribute musaDevAttrCanUseHostPointerForRegisteredMem, the memory can also be accessed from the device using the host pointer ptr. The device pointer returned by musaHostGetDevicePointer() 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 musaHostGetDevicePointer() 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 musaHostGetDevicePointer() 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 musaHostUnregister().
Parameters
ptr(void *): Host pointer to memory to page-locksize(size_t): Size in bytes of the address range to page-lock in bytesflags(unsigned int): Flags for allocation request
Returns
- musaSuccess, musaErrorInvalidValue, musaErrorMemoryAllocation, musaErrorHostMemoryAlreadyRegistered, musaErrorNotSupported
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
See also
musaHostUnregister
musaError_t musaHostUnregister(void *ptr)
Description
- Unregisters a memory range that was registered with musaHostRegister.
- Unmaps the memory range whose base address is specified by ptr, and makes it pageable again.
- The base address must be the same one specified to musaHostRegister().
Parameters
ptr(void *): Host pointer to memory to unregister
Returns
- musaSuccess, musaErrorInvalidValue, musaErrorHostMemoryNotRegistered
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
See also
musaHostGetDevicePointer
musaError_t musaHostGetDevicePointer(void **pDevice, void *pHost, unsigned int flags)
Description
- Passes back device pointer of mapped host memory allocated by musaHostAlloc or registered by musaHostRegister.
- Passes back the device pointer corresponding to the mapped, pinned host buffer allocated by musaHostAlloc() or registered by musaHostRegister().
- musaHostGetDevicePointer() will fail if the musaDeviceMapHost flag was not specified before deferred context creation occurred, or if called on a device that does not support mapped, pinned memory.
- For devices that have a non-zero value for the device attribute musaDevAttrCanUseHostPointerForRegisteredMem, the memory can also be accessed from the device using the host pointer pHost. The device pointer returned by musaHostGetDevicePointer() may or may not match the original host pointer pHost 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 musaHostGetDevicePointer() will match the original pointer pHost. If any device visible to the application has a zero value for the device attribute, the device pointer returned by musaHostGetDevicePointer() will not match the original host pointer pHost, 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.
- flags provides for future releases. For now, it must be set to 0.
Parameters
pDevice(void **): Returned device pointer for mapped memorypHost(void *): Requested host pointer mappingflags(unsigned int): Flags for extensions (must be 0 for now)
Returns
- musaSuccess, musaErrorInvalidValue, musaErrorMemoryAllocation
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
See also
musaHostGetFlags
musaError_t musaHostGetFlags(unsigned int *pFlags, void *pHost)
Description
- Passes back flags used to allocate pinned host memory allocated by musaHostAlloc.
- musaHostGetFlags() will fail if the input pointer does not reside in an address range allocated by musaHostAlloc().
Parameters
pFlags(unsigned int *): Returned flags wordpHost(void *): Host pointer
Returns
- musaSuccess, musaErrorInvalidValue
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
See also
musaMalloc3D
musaError_t musaMalloc3D(struct musaPitchedPtr *pitchedDevPtr, struct musaExtent extent)
Description
- Allocates logical 1D, 2D, or 3D memory objects on the device.
- Allocates at least width * height * depth bytes of linear memory on the device and returns a musaPitchedPtr in which ptr is a pointer to the allocated memory. The function may pad the allocation to ensure hardware alignment requirements are met. The pitch returned in the pitch field of pitchedDevPtr is the width in bytes of the allocation.
- The returned musaPitchedPtr contains additional fields xsize and ysize, the logical width and height of the allocation, which are equivalent to the width and height extent parameters provided by the programmer during allocation.
- For allocations of 2D and 3D objects, it is highly recommended that programmers perform allocations using musaMalloc3D() or musaMallocPitch(). Due to alignment restrictions in the hardware, this is especially true if the application will be performing memory copies involving 2D or 3D objects (whether linear memory or MUSA arrays).
Parameters
pitchedDevPtr(struct musaPitchedPtr *): Pointer to allocated pitched device memoryextent(struct musaExtent): Requested allocation size (width field in bytes)
Returns
- musaSuccess, musaErrorInvalidValue, musaErrorMemoryAllocation
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
See also
- musaMallocPitch, musaFree, musaMemcpy3D, musaMemset3D, musaMalloc3DArray, musaMallocArray, musaFreeArray, musaMallocHost (C API), musaFreeHost, musaHostAlloc, make_musaPitchedPtr, make_musaExtent, muMemAllocPitch
musaMalloc3DArray
musaError_t musaMalloc3DArray(musaArray_t *array, const struct musaChannelFormatDesc *desc, struct musaExtent extent, unsigned int flags)
Description
- Allocate an array on the device.
- Allocates a MUSA array according to the musaChannelFormatDesc structure desc and returns a handle to the new MUSA array in *array.
- The musaChannelFormatDesc is defined as:
struct musaChannelFormatDesc {
int x, y, z, w;
enum musaChannelFormatKind f;
};
- ; where musaChannelFormatKind is one of musaChannelFormatKindSigned, musaChannelFormatKindUnsigned, or musaChannelFormatKindFloat.
- musaMalloc3DArray() can allocate the following:
- A 1D array is allocated if the height and depth extents are both zero. A 2D array is allocated if only the 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 the height extent is zero and the musaArrayLayered 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 musaArrayLayered 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 musaArrayCubemap 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 musaGraphicsCubeFace. A cubemap layered MUSA array is allocated if all three extents are non-zero, and both, musaArrayCubemap and musaArrayLayered 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.
- The flags parameter enables different options to be specified that affect the allocation, as follows. musaArrayDefault: This flag's value is defined to be 0 and provides default array allocation musaArrayLayered: Allocates a layered MUSA array, with the depth extent indicating the number of layers musaArrayCubemap: Allocates a cubemap MUSA array. Width must be equal to height, and depth must be six. If the musaArrayLayered flag is also set, depth must be a multiple of six. musaArraySurfaceLoadStore: Allocates a MUSA array that could be read from or written to using a surface reference. musaArrayTextureGather: This flag indicates that texture gather operations will be performed on the MUSA array. Texture gather can only be performed on 2D MUSA arrays. musaArraySparse: Allocates a MUSA array without physical backing memory. The subregions within this sparse array can later be mapped onto a physical memory allocation by calling muMemMapArrayAsync. This flag can only be used for creating 2D, 3D or 2D layered sparse MUSA arrays. The physical backing memory must be allocated via muMemCreate. musaArrayDeferredMapping: Allocates a MUSA array without physical backing memory. The entire array can later be mapped onto a physical memory allocation by calling muMemMapArrayAsync. The physical backing memory must be allocated via muMemCreate.
- The width, height and depth extents must meet certain size requirements as listed in the following table. All values are specified in elements.
- Note that 2D MUSA arrays have different size requirements if the musaArrayTextureGather flag is set. In that case, the valid range for (width, height, depth) is ((1,maxTexture2DGather[0]), (1,maxTexture2DGather[1]), 0).
- MUSA array type Valid extents that must always be met {(width range in elements), (height range), (depth range)} Valid extents with musaArraySurfaceLoadStore set {(width range in elements), (height range), (depth range)} 1D { (1,maxTexture1D), 0, 0 } { (1,maxSurface1D), 0, 0 } 2D { (1,maxTexture2D[0]), (1,maxTexture2D[1]), 0 } { (1,maxSurface2D[0]), (1,maxSurface2D[1]), 0 } 3D { (1,maxTexture3D[0]), (1,maxTexture3D[1]), (1,maxTexture3D[2]) } OR { (1,maxTexture3DAlt[0]), (1,maxTexture3DAlt[1]), (1,maxTexture3DAlt[2]) } { (1,maxSurface3D[0]), (1,maxSurface3D[1]), (1,maxSurface3D[2]) } 1D Layered { (1,maxTexture1DLayered[0]), 0, (1,maxTexture1DLayered[1]) } { (1,maxSurface1DLayered[0]), 0, (1,maxSurface1DLayered[1]) } 2D Layered { (1,maxTexture2DLayered[0]), (1,maxTexture2DLayered[1]), (1,maxTexture2DLayered[2]) } { (1,maxSurface2DLayered[0]), (1,maxSurface2DLayered[1]), (1,maxSurface2DLayered[2]) } Cubemap { (1,maxTextureCubemap), (1,maxTextureCubemap), 6 } { (1,maxSurfaceCubemap), (1,maxSurfaceCubemap), 6 } Cubemap Layered { (1,maxTextureCubemapLayered[0]), (1,maxTextureCubemapLayered[0]), (1,maxTextureCubemapLayered[1]) } { (1,maxSurfaceCubemapLayered[0]), (1,maxSurfaceCubemapLayered[0]), (1,maxSurfaceCubemapLayered[1]) }
Parameters
array(musaArray_t *): Pointer to allocated array in device memorydesc(const struct musaChannelFormatDesc *): Requested channel formatextent(struct musaExtent): Requested allocation size (width field in elements)flags(unsigned int): Flags for extensions
Returns
- musaSuccess, musaErrorInvalidValue, musaErrorMemoryAllocation
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
See also
- musaMalloc3D, musaMalloc, musaMallocPitch, musaFree, musaFreeArray, musaMallocHost (C API), musaFreeHost, musaHostAlloc, make_musaExtent, muArray3DCreate
musaMallocMipmappedArray
musaError_t musaMallocMipmappedArray(musaMipmappedArray_t *mipmappedArray, const struct musaChannelFormatDesc *desc, struct musaExtent extent, unsigned int numLevels, unsigned int flags)
Description
- Allocate a mipmapped array on the device.
- Allocates a MUSA mipmapped array according to the musaChannelFormatDesc structure desc and returns a handle to the new MUSA mipmapped array in *mipmappedArray. numLevels 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 musaChannelFormatDesc is defined as:
struct musaChannelFormatDesc {
int x, y, z, w;
enum musaChannelFormatKind f;
};
- ; where musaChannelFormatKind is one of musaChannelFormatKindSigned, musaChannelFormatKindUnsigned, or musaChannelFormatKindFloat.
- musaMallocMipmappedArray() can allocate the following:
- A 1D mipmapped array is allocated if the height and depth extents are both zero. A 2D mipmapped array is allocated if only the 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 the height extent is zero and the musaArrayLayered flag is set. Each layer is a 1D mipmapped 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 musaArrayLayered flag is set. Each layer is a 2D mipmapped 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 musaArrayCubemap flag is set. Width must be equal to height, and depth must be six. The order of the six layers in memory is the same as that listed in musaGraphicsCubeFace. A cubemap layered MUSA mipmapped array is allocated if all three extents are non-zero, and both, musaArrayCubemap and musaArrayLayered flags are set. Width must be equal to height, and depth must be a multiple of six. A cubemap layered MUSA mipmapped array is a special type of 2D layered MUSA mipmapped array that consists of a collection of cubemap mipmapped arrays. The first six layers represent the first cubemap mipmapped array, the next six layers form the second cubemap mipmapped array, and so on.
- The flags parameter enables different options to be specified that affect the allocation, as follows. musaArrayDefault: This flag's value is defined to be 0 and provides default mipmapped array allocation musaArrayLayered: Allocates a layered MUSA mipmapped array, with the depth extent indicating the number of layers musaArrayCubemap: Allocates a cubemap MUSA mipmapped array. Width must be equal to height, and depth must be six. If the musaArrayLayered flag is also set, depth must be a multiple of six. musaArraySurfaceLoadStore: This flag indicates that individual mipmap levels of the MUSA mipmapped array will be read from or written to using a surface reference. musaArrayTextureGather: This flag indicates that texture gather operations will be performed on the MUSA array. Texture gather can only be performed on 2D MUSA mipmapped arrays, and the gather operations are performed only on the most detailed mipmap level. musaArraySparse: Allocates a MUSA mipmapped array without physical backing memory. The subregions within this sparse array can later be mapped onto a physical memory allocation by calling muMemMapArrayAsync. This flag can only be used for creating 2D, 3D or 2D layered sparse MUSA mipmapped arrays. The physical backing memory must be allocated via muMemCreate. musaArrayDeferredMapping: Allocates a MUSA mipmapped array without physical backing memory. The entire array can later be mapped onto a physical memory allocation by calling muMemMapArrayAsync. The physical backing memory must be allocated via muMemCreate.
- The width, height and depth extents must meet certain size requirements as listed in the following table. All values are specified in elements.
- MUSA array type Valid extents that must always be met {(width range in elements), (height range), (depth range)} Valid extents with musaArraySurfaceLoadStore set {(width range in elements), (height range), (depth range)} 1D { (1,maxTexture1DMipmap), 0, 0 } { (1,maxSurface1D), 0, 0 } 2D { (1,maxTexture2DMipmap[0]), (1,maxTexture2DMipmap[1]), 0 } { (1,maxSurface2D[0]), (1,maxSurface2D[1]), 0 } 3D { (1,maxTexture3D[0]), (1,maxTexture3D[1]), (1,maxTexture3D[2]) } OR { (1,maxTexture3DAlt[0]), (1,maxTexture3DAlt[1]), (1,maxTexture3DAlt[2]) } { (1,maxSurface3D[0]), (1,maxSurface3D[1]), (1,maxSurface3D[2]) } 1D Layered { (1,maxTexture1DLayered[0]), 0, (1,maxTexture1DLayered[1]) } { (1,maxSurface1DLayered[0]), 0, (1,maxSurface1DLayered[1]) } 2D Layered { (1,maxTexture2DLayered[0]), (1,maxTexture2DLayered[1]), (1,maxTexture2DLayered[2]) } { (1,maxSurface2DLayered[0]), (1,maxSurface2DLayered[1]), (1,maxSurface2DLayered[2]) } Cubemap { (1,maxTextureCubemap), (1,maxTextureCubemap), 6 } { (1,maxSurfaceCubemap), (1,maxSurfaceCubemap), 6 } Cubemap Layered { (1,maxTextureCubemapLayered[0]), (1,maxTextureCubemapLayered[0]), (1,maxTextureCubemapLayered[1]) } { (1,maxSurfaceCubemapLayered[0]), (1,maxSurfaceCubemapLayered[0]), (1,maxSurfaceCubemapLayered[1]) }
Parameters
mipmappedArray(musaMipmappedArray_t *): Pointer to allocated mipmapped array in device memorydesc(const struct musaChannelFormatDesc *): Requested channel formatextent(struct musaExtent): Requested allocation size (width field in elements)numLevels(unsigned int): Number of mipmap levels to allocateflags(unsigned int): Flags for extensions
Returns
- musaSuccess, musaErrorInvalidValue, musaErrorMemoryAllocation
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
See also
- musaMalloc3D, musaMalloc, musaMallocPitch, musaFree, musaFreeArray, musaMallocHost (C API), musaFreeHost, musaHostAlloc, make_musaExtent, muMipmappedArrayCreate
musaGetMipmappedArrayLevel
musaError_t musaGetMipmappedArrayLevel(musaArray_t *levelArray, musaMipmappedArray_const_t mipmappedArray, unsigned int level)
Description
- Gets a mipmap level of a MUSA mipmapped array.
- Returns in *levelArray a MUSA array that represents a single mipmap level of the MUSA mipmapped array mipmappedArray.
- If level is greater than the maximum number of levels in this mipmapped array, musaErrorInvalidValue is returned.
- If mipmappedArray is NULL, musaErrorInvalidResourceHandle is returned.
Parameters
levelArray(musaArray_t *): Returned mipmap level MUSA arraymipmappedArray(musaMipmappedArray_const_t): MUSA mipmapped arraylevel(unsigned int): Mipmap level
Returns
- musaSuccess, musaErrorInvalidValue musaErrorInvalidResourceHandle
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
See also
- musaMalloc3D, musaMalloc, musaMallocPitch, musaFree, musaFreeArray, musaMallocHost (C API), musaFreeHost, musaHostAlloc, make_musaExtent, muMipmappedArrayGetLevel
musaMemcpy3D
musaError_t musaMemcpy3D(const struct musaMemcpy3DParms *p)
Description
- Copies data between 3D objects.
struct musaExtent {
size_t width;
size_t height;
size_t depth;
};
- ;
struct musaExtent make_musaExtent(size_t w, size_t h, size_t d);
struct musaPos {
size_t x;
size_t y;
size_t z;
}
- ;
struct musaPosmake_musaPos(size_t x, size_t y, size_t z);
struct musaMemcpy3DParms {
musaArray_t srcArray;
struct musaPossrcPos;
struct musaPitchedPtrsrcPtr;
musaArray_t dstArray;
struct musaPosdstPos;
struct musaPitchedPtrdstPtr;
struct musaExtent extent;
enum musaMemcpyKindkind;
}
- ;
- musaMemcpy3D() copies data betwen two 3D objects. The source and destination objects may be in either host memory, device memory, or a MUSA array. The source, destination, extent, and kind of copy performed is specified by the musaMemcpy3DParms
struct which should be initialized to zero before use: musaMemcpy3DParmsmyParms= {
0;
}
- ;
- The struct passed to musaMemcpy3D() must specify one of srcArray or srcPtr and one of dstArray or dstPtr. Passing more than one non-zero source or destination will cause musaMemcpy3D() to return an error.
- The srcPos and dstPos fields are optional offsets into the source and destination objects and are defined in units of each object's elements. The element for a host or device pointer is assumed to be unsigned char.
- The extent field defines the dimensions of the transferred area in elements. If a MUSA array is participating in the copy, the extent is defined in terms of that array's elements. If no MUSA array is participating in the copy then the extents are defined in elements of unsigned char.
- The kind field defines the direction of the copy. It must be one of musaMemcpyHostToHost, musaMemcpyHostToDevice, musaMemcpyDeviceToHost, musaMemcpyDeviceToDevice, or musaMemcpyDefault. Passing musaMemcpyDefault is recommended, in which case the type of transfer is inferred from the pointer values. However, musaMemcpyDefault is only allowed on systems that support unified virtual addressing. For musaMemcpyHostToHost or musaMemcpyHostToDevice or musaMemcpyDeviceToHost passed as kind and musaArray type passed as source or destination, if the kind implies musaArray type to be present on the host, musaMemcpy3D() will disregard that implication and silently correct the kind based on the fact that musaArray type can only be present on the device.
- If the source and destination are both arrays, musaMemcpy3D() will return an error if they do not have the same element size.
- The source and destination object may not overlap. If overlapping source and destination objects are specified, undefined behavior will result.
- The source object must entirely contain the region defined by srcPos and extent. The destination object must entirely contain the region defined by dstPos and extent.
- musaMemcpy3D() returns an error if the pitch of srcPtr or dstPtr exceeds the maximum allowed. The pitch of a musaPitchedPtr allocated with musaMalloc3D() will always be valid.
Parameters
p(const struct musaMemcpy3DParms *): 3D memory copy parameters
Returns
- musaSuccess, musaErrorInvalidValue, musaErrorInvalidPitchValue, musaErrorInvalidMemcpyDirection
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
- See the API synchronization behavior notes for synchronization behavior.
See also
- musaMalloc3D, musaMalloc3DArray, musaMemset3D, musaMemcpy3DAsync, musaMemcpy, musaMemcpy2D, musaMemcpy2DToArray, musaMemcpy2DFromArray, musaMemcpy2DArrayToArray, musaMemcpyToSymbol, musaMemcpyFromSymbol, musaMemcpyAsync, musaMemcpy2DAsync, musaMemcpy2DToArrayAsync, musaMemcpy2DFromArrayAsync, musaMemcpyToSymbolAsync, musaMemcpyFromSymbolAsync, make_musaExtent, make_musaPos, muMemcpy3D
musaMemcpy3DPeer
musaError_t musaMemcpy3DPeer(const struct musaMemcpy3DPeerParms *p)
Description
- Copies memory between devices.
- Perform a 3D memory copy according to the parameters specified in p. See the definition of the musaMemcpy3DPeerParms structure for documentation of its parameters.
- Note that this function is synchronous with respect to the host only if the source or destination of the transfer is host memory. Note also that this copy is serialized with respect to all pending and future asynchronous work in to the current device, the copy's source device, and the copy's destination device (use musaMemcpy3DPeerAsync to avoid this synchronization).
Parameters
p(const struct musaMemcpy3DPeerParms *): Parameters for the memory copy
Returns
- musaSuccess, musaErrorInvalidValue, musaErrorInvalidDevice, musaErrorInvalidPitchValue
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
- See the API synchronization behavior notes for synchronization behavior.
See also
- musaMemcpy, musaMemcpyPeer, musaMemcpyAsync, musaMemcpyPeerAsync, musaMemcpy3DPeerAsync, muMemcpy3DPeer
musaMemcpy3DAsync
musaError_t musaMemcpy3DAsync(const struct musaMemcpy3DParms *p, musaStream_t stream)
Description
- Copies data between 3D objects.
struct musaExtent {
size_t width;
size_t height;
size_t depth;
};
- ;
struct musaExtent make_musaExtent(size_t w, size_t h, size_t d);
struct musaPos {
size_t x;
size_t y;
size_t z;
}
- ;
struct musaPosmake_musaPos(size_t x, size_t y, size_t z);
struct musaMemcpy3DParms {
musaArray_t srcArray;
struct musaPossrcPos;
struct musaPitchedPtrsrcPtr;
musaArray_t dstArray;
struct musaPosdstPos;
struct musaPitchedPtrdstPtr;
struct musaExtent extent;
enum musaMemcpyKindkind;
}
- ;
- musaMemcpy3DAsync() copies data betwen two 3D objects. The source and destination objects may be in either host memory, device memory, or a MUSA array. The source, destination, extent, and kind of copy performed is specified by the musaMemcpy3DParms
struct which should be initialized to zero before use: musaMemcpy3DParmsmyParms= {
0;
}
- ;
- The struct passed to musaMemcpy3DAsync() must specify one of srcArray or srcPtr and one of dstArray or dstPtr. Passing more than one non-zero source or destination will cause musaMemcpy3DAsync() to return an error.
- The srcPos and dstPos fields are optional offsets into the source and destination objects and are defined in units of each object's elements. The element for a host or device pointer is assumed to be unsigned char. For MUSA arrays, positions must be in the range [0, 2048) for any dimension.
- The extent field defines the dimensions of the transferred area in elements. If a MUSA array is participating in the copy, the extent is defined in terms of that array's elements. If no MUSA array is participating in the copy then the extents are defined in elements of unsigned char.
- The kind field defines the direction of the copy. It must be one of musaMemcpyHostToHost, musaMemcpyHostToDevice, musaMemcpyDeviceToHost, musaMemcpyDeviceToDevice, or musaMemcpyDefault. Passing musaMemcpyDefault is recommended, in which case the type of transfer is inferred from the pointer values. However, musaMemcpyDefault is only allowed on systems that support unified virtual addressing. For musaMemcpyHostToHost or musaMemcpyHostToDevice or musaMemcpyDeviceToHost passed as kind and musaArray type passed as source or destination, if the kind implies musaArray type to be present on the host, musaMemcpy3DAsync() will disregard that implication and silently correct the kind based on the fact that musaArray type can only be present on the device.
- If the source and destination are both arrays, musaMemcpy3DAsync() will return an error if they do not have the same element size.
- The source and destination object may not overlap. If overlapping source and destination objects are specified, undefined behavior will result.
- The source object must lie entirely within the region defined by srcPos and extent. The destination object must lie entirely within the region defined by dstPos and extent.
- musaMemcpy3DAsync() returns an error if the pitch of srcPtr or dstPtr exceeds the maximum allowed. The pitch of a musaPitchedPtr allocated with musaMalloc3D() will always be valid.
- musaMemcpy3DAsync() is asynchronous with respect to the host, so the call may return before the copy is complete. The copy can optionally be associated to a stream by passing a non-zero stream argument. If kind is musaMemcpyHostToDevice or musaMemcpyDeviceToHost and stream is non-zero, the copy may overlap with operations in other streams.
- The device version of this function only handles device to device copies and cannot be given local or shared pointers.
Parameters
p(const struct musaMemcpy3DParms *): 3D memory copy parametersstream(musaStream_t): Stream identifier
Returns
- musaSuccess, musaErrorInvalidValue, musaErrorInvalidPitchValue, musaErrorInvalidMemcpyDirection
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
- See the API synchronization behavior notes for asynchronous host/device behavior.
- See the default-stream note for NULL stream semantics.
See also
- musaMalloc3D, musaMalloc3DArray, musaMemset3D, musaMemcpy3D, musaMemcpy, musaMemcpy2D, musaMemcpy2DToArray, :musaMemcpy2DFromArray, musaMemcpy2DArrayToArray, musaMemcpyToSymbol, musaMemcpyFromSymbol, musaMemcpyAsync, musaMemcpy2DAsync, musaMemcpy2DToArrayAsync, musaMemcpy2DFromArrayAsync, musaMemcpyToSymbolAsync, musaMemcpyFromSymbolAsync, make_musaExtent, make_musaPos, muMemcpy3DAsync
musaMemcpy3DPeerAsync
musaError_t musaMemcpy3DPeerAsync(const struct musaMemcpy3DPeerParms *p, musaStream_t stream)
Description
- Copies memory between devices asynchronously.
- Perform a 3D memory copy according to the parameters specified in p. See the definition of the musaMemcpy3DPeerParms structure for documentation of its parameters.
Parameters
p(const struct musaMemcpy3DPeerParms *): Parameters for the memory copystream(musaStream_t): Stream identifier
Returns
- musaSuccess, musaErrorInvalidValue, musaErrorInvalidDevice, musaErrorInvalidPitchValue
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
- See the API synchronization behavior notes for asynchronous host/device behavior.
- See the default-stream note for NULL stream semantics.
See also
- musaMemcpy, musaMemcpyPeer, musaMemcpyAsync, musaMemcpyPeerAsync, musaMemcpy3DPeerAsync, muMemcpy3DPeerAsync
musaMemGetInfo
musaError_t musaMemGetInfo(size_t *free, size_t *total)
Description
- Gets free and total device 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
- musaSuccess, musaErrorInvalidValue, musaErrorLaunchFailure
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
See also
musaArrayGetInfo
musaError_t musaArrayGetInfo(struct musaChannelFormatDesc *desc, struct musaExtent *extent, unsigned int *flags, musaArray_t array)
Description
- Gets info about the specified musaArray.
- Returns in *desc, *extent and *flags respectively, the type, shape and flags of array.
- Any of *desc, *extent and *flags may be specified as NULL.
Parameters
desc(struct musaChannelFormatDesc *): Returned array typeextent(struct musaExtent *): Returned array shape. 2D arrays will have depth of zeroflags(unsigned int *): Returned array flagsarray(musaArray_t): The musaArray to get info for
Returns
- musaSuccess, musaErrorInvalidValue
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
See also
musaMemcpy
musaError_t musaMemcpy(void *dst, const void *src, size_t count, enum musaMemcpyKind kind)
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 musaArraySparse musaErrorInvalidValue will be returned.
- If the returned value in musaArraySparseProperties::flags contains musaArraySparsePropertiesSingleMipTail, then musaArraySparseProperties::miptailSize represents the total size of the array. Otherwise, it will be zero. Also, the returned value in musaArraySparseProperties::miptailFirstLevel is always zero. Note that the array must have been allocated using musaMallocArray or musaMalloc3DArray. For MUSA arrays obtained using musaMipmappedArrayGetLevel, musaErrorInvalidValue will be returned. Instead, musaMipmappedArrayGetSparseProperties 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 musaArraySparse musaErrorInvalidValue will be returned.
- For non-layered MUSA mipmapped arrays, musaArraySparseProperties::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 musaArraySparseProperties::flags contains musaArraySparsePropertiesSingleMipTail, then musaArraySparseProperties::miptailSize specifies the size of the mip tail of all layers combined. Otherwise, musaArraySparseProperties::miptailSize specifies mip tail size per layer. The returned value of musaArraySparseProperties::miptailFirstLevel is valid only if musaArraySparseProperties::miptailSize is non-zero.
- Copies count bytes from the memory area pointed to by src to the memory area pointed to by dst, where kind specifies the direction of the copy, and must be one of musaMemcpyHostToHost, musaMemcpyHostToDevice, musaMemcpyDeviceToHost, musaMemcpyDeviceToDevice, or musaMemcpyDefault. Passing musaMemcpyDefault is recommended, in which case the type of transfer is inferred from the pointer values. However, musaMemcpyDefault is only allowed on systems that support unified virtual addressing. Calling musaMemcpy() with dst and src pointers that do not match the direction of the copy results in an undefined behavior.
Parameters
dst(void *): Destination memory addresssrc(const void *): Source memory addresscount(size_t): Size in bytes to copykind(enum musaMemcpyKind): Type of transfer
Returns
- musaSuccess musaErrorInvalidValue
- musaSuccess, musaErrorInvalidValue, musaErrorInvalidMemcpyDirection
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
See also
- musaMipmappedArrayGetSparseProperties, muMemMapArrayAsync
- musaArrayGetSparseProperties, muMemMapArrayAsync
- musaMemcpy2D, musaMemcpy2DToArray, musaMemcpy2DFromArray, musaMemcpy2DArrayToArray, musaMemcpyToSymbol, musaMemcpyFromSymbol, musaMemcpyAsync, musaMemcpy2DAsync, musaMemcpy2DToArrayAsync, musaMemcpy2DFromArrayAsync, musaMemcpyToSymbolAsync, musaMemcpyFromSymbolAsync, muMemcpyDtoH, muMemcpyHtoD, muMemcpyDtoD, muMemcpy
musaMemcpyPeer
musaError_t musaMemcpyPeer(void *dst, int dstDevice, const void *src, int srcDevice, size_t count)
Description
- Copies memory between two devices.
- Copies memory from one device to memory on another device. dst is the base device pointer of the destination memory and dstDevice is the destination device. src is the base device pointer of the source memory and srcDevice is the source device. count specifies the number of bytes to copy.
- Note that this function is asynchronous with respect to the host, but serialized with respect all pending and future asynchronous work in to the current device, srcDevice, and dstDevice (use musaMemcpyPeerAsync to avoid this synchronization).
Parameters
dst(void *): Destination device pointerdstDevice(int): Destination devicesrc(const void *): Source device pointersrcDevice(int): Source devicecount(size_t): Size of memory copy in bytes
Returns
- musaSuccess, musaErrorInvalidValue, musaErrorInvalidDevice
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
- See the API synchronization behavior notes for synchronization behavior.
See also
musaMemcpy2D
musaError_t musaMemcpy2D(void *dst, size_t dpitch, const void *src, size_t spitch, size_t width, size_t height, enum musaMemcpyKind kind)
Description
- Copies data between host and device.
- Copies a matrix (height rows of width bytes each) from the memory area pointed to by src to the memory area pointed to by dst, where kind specifies the direction of the copy, and must be one of musaMemcpyHostToHost, musaMemcpyHostToDevice, musaMemcpyDeviceToHost, musaMemcpyDeviceToDevice, or musaMemcpyDefault. Passing musaMemcpyDefault is recommended, in which case the type of transfer is inferred from the pointer values. However, musaMemcpyDefault is only allowed on systems that support unified virtual addressing. dpitch and spitch are the widths in memory in bytes of the 2D arrays pointed to by dst and src, including any padding added to the end of each row. The memory areas may not overlap. width must not exceed either dpitch or spitch. Calling musaMemcpy2D() with dst and src pointers that do not match the direction of the copy results in an undefined behavior. musaMemcpy2D() returns an error if dpitch or spitch exceeds the maximum allowed.
Parameters
dst(void *): Destination memory addressdpitch(size_t): Pitch of destination memorysrc(const void *): Source memory addressspitch(size_t): Pitch of source memorywidth(size_t): Width of matrix transfer (columns in bytes)height(size_t): Height of matrix transfer (rows)kind(enum musaMemcpyKind): Type of transfer
Returns
- musaSuccess, musaErrorInvalidValue, musaErrorInvalidPitchValue, musaErrorInvalidMemcpyDirection
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
- See the API synchronization behavior notes for memcpy-specific synchronization semantics.
See also
- musaMemcpy, musaMemcpy2DToArray, musaMemcpy2DFromArray, musaMemcpy2DArrayToArray, musaMemcpyToSymbol, musaMemcpyFromSymbol, musaMemcpyAsync, musaMemcpy2DAsync, musaMemcpy2DToArrayAsync, musaMemcpy2DFromArrayAsync, musaMemcpyToSymbolAsync, musaMemcpyFromSymbolAsync, muMemcpy2D, muMemcpy2DUnaligned
musaMemcpy2DToArray
musaError_t musaMemcpy2DToArray(musaArray_t dst, size_t wOffset, size_t hOffset, const void *src, size_t spitch, size_t width, size_t height, enum musaMemcpyKind kind)
Description
- Copies data between host and device.
- Copies a matrix (height rows of width bytes each) from the memory area pointed to by src to the MUSA array dst starting at hOffset rows and wOffset bytes from the upper left corner, where kind specifies the direction of the copy, and must be one of musaMemcpyHostToHost, musaMemcpyHostToDevice, musaMemcpyDeviceToHost, musaMemcpyDeviceToDevice, or musaMemcpyDefault. Passing musaMemcpyDefault is recommended, in which case the type of transfer is inferred from the pointer values. However, musaMemcpyDefault is only allowed on systems that support unified virtual addressing. spitch is the width in memory in bytes of the 2D array pointed to by src, including any padding added to the end of each row. wOffset + width must not exceed the width of the MUSA array dst. width must not exceed spitch. musaMemcpy2DToArray() returns an error if spitch exceeds the maximum allowed.
Parameters
dst(musaArray_t): Destination memory addresswOffset(size_t): Destination starting X offset (columns in bytes)hOffset(size_t): Destination starting Y offset (rows)src(const void *): Source memory addressspitch(size_t): Pitch of source memorywidth(size_t): Width of matrix transfer (columns in bytes)height(size_t): Height of matrix transfer (rows)kind(enum musaMemcpyKind): Type of transfer
Returns
- musaSuccess, musaErrorInvalidValue, musaErrorInvalidPitchValue, musaErrorInvalidMemcpyDirection
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
- See the API synchronization behavior notes for memcpy-specific synchronization semantics.
- See the API synchronization behavior notes for synchronization behavior.
See also
- musaMemcpy, musaMemcpy2D, musaMemcpy2DFromArray, musaMemcpy2DArrayToArray, musaMemcpyToSymbol, musaMemcpyFromSymbol, musaMemcpyAsync, musaMemcpy2DAsync, musaMemcpy2DToArrayAsync, musaMemcpy2DFromArrayAsync, musaMemcpyToSymbolAsync, musaMemcpyFromSymbolAsync, muMemcpy2D, muMemcpy2DUnaligned
musaMemcpy2DFromArray
musaError_t musaMemcpy2DFromArray(void *dst, size_t dpitch, musaArray_const_t src, size_t wOffset, size_t hOffset, size_t width, size_t height, enum musaMemcpyKind kind)
Description
- Copies data between host and device.
- Copies a matrix (height rows of width bytes each) from the MUSA array src starting at hOffset rows and wOffset bytes from the upper left corner to the memory area pointed to by dst, where kind specifies the direction of the copy, and must be one of musaMemcpyHostToHost, musaMemcpyHostToDevice, musaMemcpyDeviceToHost, musaMemcpyDeviceToDevice, or musaMemcpyDefault. Passing musaMemcpyDefault is recommended, in which case the type of transfer is inferred from the pointer values. However, musaMemcpyDefault is only allowed on systems that support unified virtual addressing. dpitch is the width in memory in bytes of the 2D array pointed to by dst, including any padding added to the end of each row. wOffset + width must not exceed the width of the MUSA array src. width must not exceed dpitch. musaMemcpy2DFromArray() returns an error if dpitch exceeds the maximum allowed.
Parameters
dst(void *): Destination memory addressdpitch(size_t): Pitch of destination memorysrc(musaArray_const_t): Source memory addresswOffset(size_t): Source starting X offset (columns in bytes)hOffset(size_t): Source starting Y offset (rows)width(size_t): Width of matrix transfer (columns in bytes)height(size_t): Height of matrix transfer (rows)kind(enum musaMemcpyKind): Type of transfer
Returns
- musaSuccess, musaErrorInvalidValue, musaErrorInvalidPitchValue, musaErrorInvalidMemcpyDirection
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
- See the API synchronization behavior notes for memcpy-specific synchronization semantics.
- See the API synchronization behavior notes for synchronization behavior.
See also
- musaMemcpy, musaMemcpy2D, musaMemcpy2DToArray, musaMemcpy2DArrayToArray, musaMemcpyToSymbol, musaMemcpyFromSymbol, musaMemcpyAsync, musaMemcpy2DAsync, musaMemcpy2DToArrayAsync, musaMemcpy2DFromArrayAsync, musaMemcpyToSymbolAsync, musaMemcpyFromSymbolAsync, muMemcpy2D, muMemcpy2DUnaligned
musaMemcpy2DArrayToArray
musaError_t musaMemcpy2DArrayToArray(musaArray_t dst, size_t wOffsetDst, size_t hOffsetDst, musaArray_const_t src, size_t wOffsetSrc, size_t hOffsetSrc, size_t width, size_t height, enum musaMemcpyKind kind)
Description
- Copies data between host and device.
- Copies a matrix (height rows of width bytes each) from the MUSA array src starting at hOffsetSrc rows and wOffsetSrc bytes from the upper left corner to the MUSA array dst starting at hOffsetDst rows and wOffsetDst bytes from the upper left corner, where kind specifies the direction of the copy, and must be one of musaMemcpyHostToHost, musaMemcpyHostToDevice, musaMemcpyDeviceToHost, musaMemcpyDeviceToDevice, or musaMemcpyDefault. Passing musaMemcpyDefault is recommended, in which case the type of transfer is inferred from the pointer values. However, musaMemcpyDefault is only allowed on systems that support unified virtual addressing. wOffsetDst + width must not exceed the width of the MUSA array dst. wOffsetSrc + width must not exceed the width of the MUSA array src.
Parameters
dst(musaArray_t): Destination memory addresswOffsetDst(size_t): Destination starting X offset (columns in bytes)hOffsetDst(size_t): Destination starting Y offset (rows)src(musaArray_const_t): Source memory addresswOffsetSrc(size_t): Source starting X offset (columns in bytes)hOffsetSrc(size_t): Source starting Y offset (rows)width(size_t): Width of matrix transfer (columns in bytes)height(size_t): Height of matrix transfer (rows)kind(enum musaMemcpyKind): Type of transfer
Returns
- musaSuccess, musaErrorInvalidValue, musaErrorInvalidMemcpyDirection
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
- See the API synchronization behavior notes for synchronization behavior.
See also
- musaMemcpy, musaMemcpy2D, musaMemcpy2DToArray, musaMemcpy2DFromArray, musaMemcpyToSymbol, musaMemcpyFromSymbol, musaMemcpyAsync, musaMemcpy2DAsync, musaMemcpy2DToArrayAsync, musaMemcpy2DFromArrayAsync, musaMemcpyToSymbolAsync, musaMemcpyFromSymbolAsync, muMemcpy2D, muMemcpy2DUnaligned
musaMemcpyToSymbol
musaError_t musaMemcpyToSymbol(const void *symbol, const void *src, size_t count, size_t offset, enum musaMemcpyKind kind)
Description
- Copies data to the given symbol on the device.
- Copies count bytes from the memory area pointed to by src to the memory area pointed to by offset bytes from the start of symbol symbol. The memory areas may not overlap. symbol is a variable that resides in global or constant memory space. kind can be either musaMemcpyHostToDevice, musaMemcpyDeviceToDevice, or musaMemcpyDefault. Passing musaMemcpyDefault is recommended, in which case the type of transfer is inferred from the pointer values. However, musaMemcpyDefault is only allowed on systems that support unified virtual addressing.
Parameters
symbol(const void *): Device symbol addresssrc(const void *): Source memory addresscount(size_t): Size in bytes to copyoffset(size_t): Offset from start of symbol in byteskind(enum musaMemcpyKind): Type of transfer
Returns
- musaSuccess, musaErrorInvalidValue, musaErrorInvalidSymbol, musaErrorInvalidMemcpyDirection, musaErrorNoKernelImageForDevice
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
- See the API synchronization behavior notes for synchronization behavior.
- This string-based API is deprecated.
See also
- musaMemcpy, musaMemcpy2D, musaMemcpy2DToArray, musaMemcpy2DFromArray, musaMemcpy2DArrayToArray, musaMemcpyFromSymbol, musaMemcpyAsync, musaMemcpy2DAsync, musaMemcpy2DToArrayAsync, musaMemcpy2DFromArrayAsync, musaMemcpyToSymbolAsync, musaMemcpyFromSymbolAsync, muMemcpy, muMemcpyHtoD, muMemcpyDtoD
musaMemcpyFromSymbol
musaError_t musaMemcpyFromSymbol(void *dst, const void *symbol, size_t count, size_t offset, enum musaMemcpyKind kind)
Description
- Copies data from the given symbol on the device.
- Copies count bytes from the memory area pointed to by offset bytes from the start of symbol symbol to the memory area pointed to by dst. The memory areas may not overlap. symbol is a variable that resides in global or constant memory space. kind can be either musaMemcpyDeviceToHost, musaMemcpyDeviceToDevice, or musaMemcpyDefault. Passing musaMemcpyDefault is recommended, in which case the type of transfer is inferred from the pointer values. However, musaMemcpyDefault is only allowed on systems that support unified virtual addressing.
Parameters
dst(void *): Destination memory addresssymbol(const void *): Device symbol addresscount(size_t): Size in bytes to copyoffset(size_t): Offset from start of symbol in byteskind(enum musaMemcpyKind): Type of transfer
Returns
- musaSuccess, musaErrorInvalidValue, musaErrorInvalidSymbol, musaErrorInvalidMemcpyDirection, musaErrorNoKernelImageForDevice
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
- See the API synchronization behavior notes for synchronization behavior.
- This string-based API is deprecated.
See also
- musaMemcpy, musaMemcpy2D, musaMemcpy2DToArray, musaMemcpy2DFromArray, musaMemcpy2DArrayToArray, musaMemcpyToSymbol, musaMemcpyAsync, musaMemcpy2DAsync, musaMemcpy2DToArrayAsync, musaMemcpy2DFromArrayAsync, musaMemcpyToSymbolAsync, musaMemcpyFromSymbolAsync, muMemcpy, muMemcpyDtoH, muMemcpyDtoD
musaMemcpyAsync
musaError_t musaMemcpyAsync(void *dst, const void *src, size_t count, enum musaMemcpyKind kind, musaStream_t stream)
Description
- Copies data between host and device.
- Copies count bytes from the memory area pointed to by src to the memory area pointed to by dst, where kind specifies the direction of the copy, and must be one of musaMemcpyHostToHost, musaMemcpyHostToDevice, musaMemcpyDeviceToHost, musaMemcpyDeviceToDevice, or musaMemcpyDefault. Passing musaMemcpyDefault is recommended, in which case the type of transfer is inferred from the pointer values. However, musaMemcpyDefault is only allowed on systems that support unified virtual addressing.
- The memory areas may not overlap. Calling musaMemcpyAsync() with dst and src pointers that do not match the direction of the copy results in an undefined behavior.
- musaMemcpyAsync() is asynchronous with respect to the host, so the call may return before the copy is complete. The copy can optionally be associated to a stream by passing a non-zero stream argument. If kind is musaMemcpyHostToDevice or musaMemcpyDeviceToHost and the stream is non-zero, the copy may overlap with operations in other streams.
- The device version of this function only handles device to device copies and cannot be given local or shared pointers.
Parameters
dst(void *): Destination memory addresssrc(const void *): Source memory addresscount(size_t): Size in bytes to copykind(enum musaMemcpyKind): Type of transferstream(musaStream_t): Stream identifier
Returns
- musaSuccess, musaErrorInvalidValue, musaErrorInvalidMemcpyDirection
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
- 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
- musaMemcpy, musaMemcpy2D, musaMemcpy2DToArray, musaMemcpy2DFromArray, musaMemcpy2DArrayToArray, musaMemcpyToSymbol, musaMemcpyFromSymbol, musaMemcpy2DAsync, musaMemcpy2DToArrayAsync, musaMemcpy2DFromArrayAsync, musaMemcpyToSymbolAsync, musaMemcpyFromSymbolAsync, muMemcpyAsync, muMemcpyDtoHAsync, muMemcpyHtoDAsync, muMemcpyDtoDAsync
musaMemcpyPeerAsync
musaError_t musaMemcpyPeerAsync(void *dst, int dstDevice, const void *src, int srcDevice, size_t count, musaStream_t stream)
Description
- Copies memory between two devices asynchronously.
- Copies memory from one device to memory on another device. dst is the base device pointer of the destination memory and dstDevice is the destination device. src is the base device pointer of the source memory and srcDevice is the source device. count specifies the number of bytes to copy.
- Note that this function is asynchronous with respect to the host and all work on other devices.
Parameters
dst(void *): Destination device pointerdstDevice(int): Destination devicesrc(const void *): Source device pointersrcDevice(int): Source devicecount(size_t): Size of memory copy in bytesstream(musaStream_t): Stream identifier
Returns
- musaSuccess, musaErrorInvalidValue, musaErrorInvalidDevice
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
- See the API synchronization behavior notes for asynchronous host/device behavior.
- See the default-stream note for NULL stream semantics.
See also
musaMemcpyBatchAsync
musaError_t musaMemcpyBatchAsync(void **dsts, void **srcs, size_t *sizes, size_t count, struct musaMemcpyAttributes *attrs, size_t *attrsIdxs, size_t numAttrs, size_t *failIdx, musaStream_t stream)
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 musaMemcpy3DBatchAsync.
- 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 musaMemcpyAttributes::srcAccessOrder indicates the source access ordering to be observed for copies associated with the attribute. If the source access order is set to musaMemcpySrcAccessOrderStream, then the source will be accessed in stream order. If the source access order is set to musaMemcpySrcAccessOrderDuringApiCall 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 musaMemcpySrcAccessOrderAny 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 musaMemcpyAttributes corresponding to it including the appropriate srcAccessOrder setting, otherwise the API will return musaErrorInvalidValue.
- The musaMemcpyAttributes::srcLocHint and musaMemcpyAttributes::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 musaDevAttrConcurrentManagedAccess is true or system-allocated pageable memory on devices where musaDevAttrPageableMemoryAccess is true. For other cases, these hints are ignored.
- The musaMemcpyAttributes::flags field can be used to specify certain flags for copies. Setting the musaMemcpyFlagPreferOverlapWithCompute 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(void **): Array of destination pointers.srcs(void **): Array of memcpy source pointers.sizes(size_t *): Array of sizes for memcpy operations.count(size_t): Size of dsts, srcs and sizes arraysattrs(struct musaMemcpyAttributes *): 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.stream(musaStream_t)
Returns
- musaSuccess musaErrorInvalidValue
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.
musaMemcpy3DBatchAsync
musaError_t musaMemcpy3DBatchAsync(size_t numOps, struct musaMemcpy3DBatchOp *opList, size_t *failIdx, unsigned long long flags, musaStream_t stream)
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 musaMemcpy3DBatchOp::src and musaMemcpy3DBatchOp::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 musaMemcpy3DBatchOp::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 musaMemcpy3DOperand::type is specified as musaMemcpyOperandTypePointer, then musaMemcpy3DOperand::op::ptr will be used. The musaMemcpy3DOperand::op::ptr::ptr field must contain the pointer where the copy should begin. The musaMemcpy3DOperand::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 musaMemcpy3DBatchOp::extent::width. The musaMemcpy3DOperand::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 musaMemcpy3DBatchOp::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 musaDevAttrConcurrentManagedAccess is true or system-allocated pageable memory on devices where musaDevAttrPageableMemoryAccess is true, the musaMemcpy3DOperand::op::ptr::locHint field can be used to hint the location of the operand.
- If an operand's type is specified as musaMemcpyOperandTypeArray, then musaMemcpy3DOperand::op::array will be used. The musaMemcpy3DOperand::op::array::array field specifies the MUSA array and musaMemcpy3DOperand::op::array::offset specifies the 3D offset into that array where the copy begins.
- The musaMemcpyAttributes::srcAccessOrder indicates the source access ordering to be observed for copies associated with the attribute. If the source access order is set to musaMemcpySrcAccessOrderStream, then the source will be accessed in stream order. If the source access order is set to musaMemcpySrcAccessOrderDuringApiCall 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 musaMemcpySrcAccessOrderAny 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 musaErrorInvalidValue.
- The musaMemcpyAttributes::flags field can be used to specify certain flags for copies. Setting the musaMemcpyFlagPreferOverlapWithCompute 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(struct musaMemcpy3DBatchOp *): 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.stream(musaStream_t)
Returns
- musaSuccess musaErrorInvalidValue
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.
musaMemcpy2DAsync
musaError_t musaMemcpy2DAsync(void *dst, size_t dpitch, const void *src, size_t spitch, size_t width, size_t height, enum musaMemcpyKind kind, musaStream_t stream)
Description
- Copies data between host and device.
- 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 musaMemcpyAttributes and it's usage desciption in::musaMemcpyBatchAsync
- For more information regarding the operation, please refer to musaMemcpy3DBatchOp and it's usage desciption in::musaMemcpy3DBatchAsync
- Calling musaMemcpy2DAsync() with dst and src pointers that do not match the direction of the copy results in an undefined behavior. musaMemcpy2DAsync() returns an error if dpitch or spitch is greater than the maximum allowed.
- musaMemcpy2DAsync() is asynchronous with respect to the host, so the call may return before the copy is complete. The copy can optionally be associated to a stream by passing a non-zero stream argument. If kind is musaMemcpyHostToDevice or musaMemcpyDeviceToHost and stream is non-zero, the copy may overlap with operations in other streams.
- The device version of this function only handles device to device copies and cannot be given local or shared pointers.
Parameters
dst(void *): Destination memory addressdpitch(size_t): Pitch of destination memorysrc(const void *): Source memory addressspitch(size_t): Pitch of source memorywidth(size_t): Width of matrix transfer (columns in bytes)height(size_t): Height of matrix transfer (rows)kind(enum musaMemcpyKind): Type of transferstream(musaStream_t): Stream identifier
Returns
- musaSuccess, musaErrorInvalidValue
- musaSuccess, musaErrorInvalidValue, musaErrorInvalidPitchValue, musaErrorInvalidMemcpyDirection
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.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
- See the default-stream note for NULL stream semantics.
See also
- musaMemcpyBatchAsync Performs 3D asynchronous memory copy with the specified attributes.
- musaMemcpy3DBatchAsync
- musaMemcpy, musaMemcpy2D, musaMemcpy2DToArray, musaMemcpy2DFromArray, musaMemcpy2DArrayToArray, musaMemcpyToSymbol, musaMemcpyFromSymbol, musaMemcpyAsync, musaMemcpy2DToArrayAsync, musaMemcpy2DFromArrayAsync, musaMemcpyToSymbolAsync, musaMemcpyFromSymbolAsync, muMemcpy2DAsync
musaMemcpy2DToArrayAsync
musaError_t musaMemcpy2DToArrayAsync(musaArray_t dst, size_t wOffset, size_t hOffset, const void *src, size_t spitch, size_t width, size_t height, enum musaMemcpyKind kind, musaStream_t stream)
Description
- Copies data between host and device.
- Copies a matrix (height rows of width bytes each) from the memory area pointed to by src to the MUSA array dst starting at hOffset rows and wOffset bytes from the upper left corner, where kind specifies the direction of the copy, and must be one of musaMemcpyHostToHost, musaMemcpyHostToDevice, musaMemcpyDeviceToHost, musaMemcpyDeviceToDevice, or musaMemcpyDefault. Passing musaMemcpyDefault is recommended, in which case the type of transfer is inferred from the pointer values. However, musaMemcpyDefault is only allowed on systems that support unified virtual addressing. spitch is the width in memory in bytes of the 2D array pointed to by src, including any padding added to the end of each row. wOffset + width must not exceed the width of the MUSA array dst. width must not exceed spitch. musaMemcpy2DToArrayAsync() returns an error if spitch exceeds the maximum allowed.
- musaMemcpy2DToArrayAsync() is asynchronous with respect to the host, so the call may return before the copy is complete. The copy can optionally be associated to a stream by passing a non-zero stream argument. If kind is musaMemcpyHostToDevice or musaMemcpyDeviceToHost and stream is non-zero, the copy may overlap with operations in other streams.
Parameters
dst(musaArray_t): Destination memory addresswOffset(size_t): Destination starting X offset (columns in bytes)hOffset(size_t): Destination starting Y offset (rows)src(const void *): Source memory addressspitch(size_t): Pitch of source memorywidth(size_t): Width of matrix transfer (columns in bytes)height(size_t): Height of matrix transfer (rows)kind(enum musaMemcpyKind): Type of transferstream(musaStream_t): Stream identifier
Returns
- musaSuccess, musaErrorInvalidValue, musaErrorInvalidPitchValue, musaErrorInvalidMemcpyDirection
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
- 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
- musaMemcpy, musaMemcpy2D, musaMemcpy2DToArray, musaMemcpy2DFromArray, musaMemcpy2DArrayToArray, musaMemcpyToSymbol, musaMemcpyFromSymbol, musaMemcpyAsync, musaMemcpy2DAsync,
musaMemcpy2DFromArrayAsync
musaError_t musaMemcpy2DFromArrayAsync(void *dst, size_t dpitch, musaArray_const_t src, size_t wOffset, size_t hOffset, size_t width, size_t height, enum musaMemcpyKind kind, musaStream_t stream)
Description
- Copies data between host and device.
- Copies a matrix (height rows of width bytes each) from the MUSA array src starting at hOffset rows and wOffset bytes from the upper left corner to the memory area pointed to by dst, where kind specifies the direction of the copy, and must be one of musaMemcpyHostToHost, musaMemcpyHostToDevice, musaMemcpyDeviceToHost, musaMemcpyDeviceToDevice, or musaMemcpyDefault. Passing musaMemcpyDefault is recommended, in which case the type of transfer is inferred from the pointer values. However, musaMemcpyDefault is only allowed on systems that support unified virtual addressing. dpitch is the width in memory in bytes of the 2D array pointed to by dst, including any padding added to the end of each row. wOffset + width must not exceed the width of the MUSA array src. width must not exceed dpitch. musaMemcpy2DFromArrayAsync() returns an error if dpitch exceeds the maximum allowed.
- musaMemcpy2DFromArrayAsync() is asynchronous with respect to the host, so the call may return before the copy is complete. The copy can optionally be associated to a stream by passing a non-zero stream argument. If kind is musaMemcpyHostToDevice or musaMemcpyDeviceToHost and stream is non-zero, the copy may overlap with operations in other streams.
Parameters
dst(void *): Destination memory addressdpitch(size_t): Pitch of destination memorysrc(musaArray_const_t): Source memory addresswOffset(size_t): Source starting X offset (columns in bytes)hOffset(size_t): Source starting Y offset (rows)width(size_t): Width of matrix transfer (columns in bytes)height(size_t): Height of matrix transfer (rows)kind(enum musaMemcpyKind): Type of transferstream(musaStream_t): Stream identifier
Returns
- musaSuccess, musaErrorInvalidValue, musaErrorInvalidPitchValue, musaErrorInvalidMemcpyDirection
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
- 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
- musaMemcpy, musaMemcpy2D, musaMemcpy2DToArray, musaMemcpy2DFromArray, musaMemcpy2DArrayToArray, musaMemcpyToSymbol, musaMemcpyFromSymbol, musaMemcpyAsync, musaMemcpy2DAsync, musaMemcpy2DToArrayAsync,
musaMemcpyToSymbolAsync
musaError_t musaMemcpyToSymbolAsync(const void *symbol, const void *src, size_t count, size_t offset, enum musaMemcpyKind kind, musaStream_t stream)
Description
- Copies data to the given symbol on the device.
- Copies count bytes from the memory area pointed to by src to the memory area pointed to by offset bytes from the start of symbol symbol. The memory areas may not overlap. symbol is a variable that resides in global or constant memory space. kind can be either musaMemcpyHostToDevice, musaMemcpyDeviceToDevice, or musaMemcpyDefault. Passing musaMemcpyDefault is recommended, in which case the type of transfer is inferred from the pointer values. However, musaMemcpyDefault is only allowed on systems that support unified virtual addressing.
- musaMemcpyToSymbolAsync() is asynchronous with respect to the host, so the call may return before the copy is complete. The copy can optionally be associated to a stream by passing a non-zero stream argument. If kind is musaMemcpyHostToDevice and stream is non-zero, the copy may overlap with operations in other streams.
Parameters
symbol(const void *): Device symbol addresssrc(const void *): Source memory addresscount(size_t): Size in bytes to copyoffset(size_t): Offset from start of symbol in byteskind(enum musaMemcpyKind): Type of transferstream(musaStream_t): Stream identifier
Returns
- musaSuccess, musaErrorInvalidValue, musaErrorInvalidSymbol, musaErrorInvalidMemcpyDirection, musaErrorNoKernelImageForDevice
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
- See the API synchronization behavior notes for asynchronous host/device behavior.
- See the default-stream note for NULL stream semantics.
- This string-based API is deprecated.
See also
- musaMemcpy, musaMemcpy2D, musaMemcpy2DToArray, musaMemcpy2DFromArray, musaMemcpy2DArrayToArray, musaMemcpyToSymbol, musaMemcpyFromSymbol, musaMemcpyAsync, musaMemcpy2DAsync, musaMemcpy2DToArrayAsync, musaMemcpy2DFromArrayAsync, musaMemcpyFromSymbolAsync, muMemcpyAsync, muMemcpyHtoDAsync, muMemcpyDtoDAsync
musaMemcpyFromSymbolAsync
musaError_t musaMemcpyFromSymbolAsync(void *dst, const void *symbol, size_t count, size_t offset, enum musaMemcpyKind kind, musaStream_t stream)
Description
- Copies data from the given symbol on the device.
- Copies count bytes from the memory area pointed to by offset bytes from the start of symbol symbol to the memory area pointed to by dst. The memory areas may not overlap. symbol is a variable that resides in global or constant memory space. kind can be either musaMemcpyDeviceToHost, musaMemcpyDeviceToDevice, or musaMemcpyDefault. Passing musaMemcpyDefault is recommended, in which case the type of transfer is inferred from the pointer values. However, musaMemcpyDefault is only allowed on systems that support unified virtual addressing.
- musaMemcpyFromSymbolAsync() is asynchronous with respect to the host, so the call may return before the copy is complete. The copy can optionally be associated to a stream by passing a non-zero stream argument. If kind is musaMemcpyDeviceToHost and stream is non-zero, the copy may overlap with operations in other streams.
Parameters
dst(void *): Destination memory addresssymbol(const void *): Device symbol addresscount(size_t): Size in bytes to copyoffset(size_t): Offset from start of symbol in byteskind(enum musaMemcpyKind): Type of transferstream(musaStream_t): Stream identifier
Returns
- musaSuccess, musaErrorInvalidValue, musaErrorInvalidSymbol, musaErrorInvalidMemcpyDirection, musaErrorNoKernelImageForDevice
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
- See the API synchronization behavior notes for asynchronous host/device behavior.
- See the default-stream note for NULL stream semantics.
- This string-based API is deprecated.
See also
- musaMemcpy, musaMemcpy2D, musaMemcpy2DToArray, musaMemcpy2DFromArray, musaMemcpy2DArrayToArray, musaMemcpyToSymbol, musaMemcpyFromSymbol, musaMemcpyAsync, musaMemcpy2DAsync, musaMemcpy2DToArrayAsync, musaMemcpy2DFromArrayAsync, musaMemcpyToSymbolAsync, muMemcpyAsync, muMemcpyDtoHAsync, muMemcpyDtoDAsync
musaMemset
musaError_t musaMemset(void *devPtr, int value, size_t count)
Description
- Initializes or sets device memory to a value.
- Fills the first count bytes of the memory area pointed to by devPtr with the constant byte value value.
- Note that this function is asynchronous with respect to the host unless devPtr refers to pinned host memory.
Parameters
devPtr(void *): Pointer to device memoryvalue(int): Value to set for each byte of specified memorycount(size_t): Size in bytes to set
Returns
- musaSuccess, musaErrorInvalidValue
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
- See the API synchronization behavior notes for memset-specific synchronization semantics.
See also
musaMemset2D
musaError_t musaMemset2D(void *devPtr, size_t pitch, int value, size_t width, size_t height)
Description
- Initializes or sets device memory to a value.
- Sets to the specified value value a matrix (height rows of width bytes each) pointed to by dstPtr. pitch is the width in bytes of the 2D array pointed to by dstPtr, including any padding added to the end of each row. This function performs fastest when the pitch is one that has been passed back by musaMallocPitch().
- Note that this function is asynchronous with respect to the host unless devPtr refers to pinned host memory.
Parameters
devPtr(void *): Pointer to 2D device memorypitch(size_t): Pitch in bytes of 2D device memory(Unused if height is 1)value(int): Value to set for each byte of specified memorywidth(size_t): Width of matrix set (columns in bytes)height(size_t): Height of matrix set (rows)
Returns
- musaSuccess, musaErrorInvalidValue
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
- See the API synchronization behavior notes for memset-specific synchronization semantics.
See also
- musaMemset, musaMemset3D, musaMemsetAsync, musaMemset2DAsync, musaMemset3DAsync, muMemsetD2D8, muMemsetD2D16, muMemsetD2D32
musaMemset3D
musaError_t musaMemset3D(struct musaPitchedPtr pitchedDevPtr, int value, struct musaExtent extent)
Description
- Initializes or sets device memory to a value.
- Initializes each element of a 3D array to the specified value value. The object to initialize is defined by pitchedDevPtr. The pitch field of pitchedDevPtr is the width in memory in bytes of the 3D array pointed to by pitchedDevPtr, including any padding added to the end of each row. The xsize field specifies the logical width of each row in bytes, while the ysize field specifies the height of each 2D slice in rows. The pitch field of pitchedDevPtr is ignored when height and depth are both equal to 1.
- The extents of the initialized region are specified as a width in bytes, a height in rows, and a depth in slices.
- Extents with width greater than or equal to the xsize of pitchedDevPtr may perform significantly faster than extents narrower than the xsize. Secondarily, extents with height equal to the ysize of pitchedDevPtr will perform faster than when the height is shorter than the ysize.
- This function performs fastest when the pitchedDevPtr has been allocated by musaMalloc3D().
- Note that this function is asynchronous with respect to the host unless pitchedDevPtr refers to pinned host memory.
Parameters
pitchedDevPtr(struct musaPitchedPtr): Pointer to pitched device memoryvalue(int): Value to set for each byte of specified memoryextent(struct musaExtent): Size parameters for where to set device memory (width field in bytes)
Returns
- musaSuccess, musaErrorInvalidValue
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
- See the API synchronization behavior notes for memset-specific synchronization semantics.
See also
- musaMemset, musaMemset2D, musaMemsetAsync, musaMemset2DAsync, musaMemset3DAsync, musaMalloc3D, make_musaPitchedPtr, make_musaExtent
musaMemsetAsync
musaError_t musaMemsetAsync(void *devPtr, int value, size_t count, musaStream_t stream)
Description
- Initializes or sets device memory to a value.
- Fills the first count bytes of the memory area pointed to by devPtr with the constant byte value value.
- musaMemsetAsync() is asynchronous with respect to the host, so the call may return before the memset is complete. The operation can optionally be associated to a stream by passing a non-zero stream argument. If stream is non-zero, the operation may overlap with operations in other streams.
- The device version of this function only handles device to device copies and cannot be given local or shared pointers.
Parameters
devPtr(void *): Pointer to device memoryvalue(int): Value to set for each byte of specified memorycount(size_t): Size in bytes to setstream(musaStream_t): Stream identifier
Returns
- musaSuccess, musaErrorInvalidValue
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
- See the API synchronization behavior notes for memset-specific synchronization semantics.
- See the default-stream note for NULL stream semantics.
See also
- musaMemset, musaMemset2D, musaMemset3D, musaMemset2DAsync, musaMemset3DAsync, muMemsetD8Async, muMemsetD16Async, muMemsetD32Async
musaMemset2DAsync
musaError_t musaMemset2DAsync(void *devPtr, size_t pitch, int value, size_t width, size_t height, musaStream_t stream)
Description
- Initializes or sets device memory to a value.
- Sets to the specified value value a matrix (height rows of width bytes each) pointed to by dstPtr. pitch is the width in bytes of the 2D array pointed to by dstPtr, including any padding added to the end of each row. This function performs fastest when the pitch is one that has been passed back by musaMallocPitch().
- musaMemset2DAsync() is asynchronous with respect to the host, so the call may return before the memset is complete. The operation can optionally be associated to a stream by passing a non-zero stream argument. If stream is non-zero, the operation may overlap with operations in other streams.
- The device version of this function only handles device to device copies and cannot be given local or shared pointers.
Parameters
devPtr(void *): Pointer to 2D device memorypitch(size_t): Pitch in bytes of 2D device memory(Unused if height is 1)value(int): Value to set for each byte of specified memorywidth(size_t): Width of matrix set (columns in bytes)height(size_t): Height of matrix set (rows)stream(musaStream_t): Stream identifier
Returns
- musaSuccess, musaErrorInvalidValue
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
- See the API synchronization behavior notes for memset-specific synchronization semantics.
- See the default-stream note for NULL stream semantics.
See also
- musaMemset, musaMemset2D, musaMemset3D, musaMemsetAsync, musaMemset3DAsync, muMemsetD2D8Async, muMemsetD2D16Async, muMemsetD2D32Async
musaMemset3DAsync
musaError_t musaMemset3DAsync(struct musaPitchedPtr pitchedDevPtr, int value, struct musaExtent extent, musaStream_t stream)
Description
- Initializes or sets device memory to a value.
- Initializes each element of a 3D array to the specified value value. The object to initialize is defined by pitchedDevPtr. The pitch field of pitchedDevPtr is the width in memory in bytes of the 3D array pointed to by pitchedDevPtr, including any padding added to the end of each row. The xsize field specifies the logical width of each row in bytes, while the ysize field specifies the height of each 2D slice in rows. The pitch field of pitchedDevPtr is ignored when height and depth are both equal to 1.
- The extents of the initialized region are specified as a width in bytes, a height in rows, and a depth in slices.
- Extents with width greater than or equal to the xsize of pitchedDevPtr may perform significantly faster than extents narrower than the xsize. Secondarily, extents with height equal to the ysize of pitchedDevPtr will perform faster than when the height is shorter than the ysize.
- This function performs fastest when the pitchedDevPtr has been allocated by musaMalloc3D().
- musaMemset3DAsync() is asynchronous with respect to the host, so the call may return before the memset is complete. The operation can optionally be associated to a stream by passing a non-zero stream argument. If stream is non-zero, the operation may overlap with operations in other streams.
- The device version of this function only handles device to device copies and cannot be given local or shared pointers.
Parameters
pitchedDevPtr(struct musaPitchedPtr): Pointer to pitched device memoryvalue(int): Value to set for each byte of specified memoryextent(struct musaExtent): Size parameters for where to set device memory (width field in bytes)stream(musaStream_t): Stream identifier
Returns
- musaSuccess, musaErrorInvalidValue
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
- See the API synchronization behavior notes for memset-specific synchronization semantics.
- See the default-stream note for NULL stream semantics.
See also
- musaMemset, musaMemset2D, musaMemset3D, musaMemsetAsync, musaMemset2DAsync, musaMalloc3D, make_musaPitchedPtr, make_musaExtent
musaGetSymbolAddress
musaError_t musaGetSymbolAddress(void **devPtr, const void *symbol)
Description
- Finds the address associated with a MUSA symbol.
- Returns in *devPtr the address of symbol symbol on the device. symbol is a variable that resides in global or constant memory space. If symbol cannot be found, or if symbol is not declared in the global or constant memory space, *devPtr is unchanged and the error musaErrorInvalidSymbol is returned.
Parameters
devPtr(void **): Return device pointer associated with symbolsymbol(const void *): Device symbol address
Returns
- musaSuccess, musaErrorInvalidSymbol, musaErrorNoKernelImageForDevice
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
- This string-based API is deprecated.
See also
- musaGetSymbolAddress (C++ API), musaGetSymbolSize (C API), muModuleGetGlobal
musaGetSymbolSize
musaError_t musaGetSymbolSize(size_t *size, const void *symbol)
Description
- Finds the size of the object associated with a MUSA symbol.
- Returns in *size the size of symbol symbol. symbol is a variable that resides in global or constant memory space. If symbol cannot be found, or if symbol is not declared in global or constant memory space, *size is unchanged and the error musaErrorInvalidSymbol is returned.
Parameters
size(size_t *): Size of object associated with symbolsymbol(const void *): Device symbol address
Returns
- musaSuccess, musaErrorInvalidSymbol, musaErrorNoKernelImageForDevice
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
- This string-based API is deprecated.
See also
- musaGetSymbolAddress (C API), musaGetSymbolSize (C++ API), muModuleGetGlobal
musaMemPrefetchAsync
musaError_t musaMemPrefetchAsync(const void *devPtr, size_t count, int dstDevice, musaStream_t stream)
Description
- Prefetches memory to the specified destination device.
- 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. stream is the stream in which the operation is enqueued. The memory range must refer to managed memory allocated via musaMallocManaged or declared via managed variables, or it may also refer to system-allocated memory on systems with non-zero musaDevAttrPageableMemoryAccess.
- Passing in musaCpuDeviceId for dstDevice will prefetch the data to host memory. If dstDevice is a GPU, then the device attribute musaDevAttrConcurrentManagedAccess must be non-zero. Additionally, stream must be associated with a device that has a non-zero value for the device attribute musaDevAttrConcurrentManagedAccess.
- 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 musaMallocManaged allocations to host memory in order to make room. Device memory allocated using musaMalloc or musaMallocArray 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 musaMemAdvise as described below:
- If musaMemAdviseSetReadMostly was set on any subset of this memory range, then that subset will create a read-only copy of the pages on dstDevice.
- If musaMemAdviseSetPreferredLocation 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 musaMemAdviseSetAccessedBy 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(const void *): Pointer to be prefetchedcount(size_t): Size in bytesdstDevice(int): Destination device to prefetch tostream(musaStream_t): Stream to enqueue prefetch operation
Returns
- musaSuccess, musaErrorInvalidValue, musaErrorInvalidDevice
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
- See the API synchronization behavior notes for asynchronous host/device behavior.
- See the default-stream note for NULL stream semantics.
See also
- musaMemcpy, musaMemcpyPeer, musaMemcpyAsync, musaMemcpy3DPeerAsync, musaMemAdvise, musaMemAdvise_v2 muMemPrefetchAsync
musaMemPrefetchAsync_v2
musaError_t musaMemPrefetchAsync_v2(const void *devPtr, size_t count, struct musaMemLocation location, unsigned int flags, musaStream_t stream)
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. stream is the stream in which the operation is enqueued. The memory range must refer to managed memory allocated via musaMallocManaged or declared via managed variables, or it may also refer to system-allocated memory on systems with non-zero musaDevAttrPageableMemoryAccess.
- Specifying musaMemLocationTypeDevice for musaMemLocation::type will prefetch memory to GPU specified by device ordinal musaMemLocation::id which must have non-zero value for the device attribute concurrentManagedAccess. Additionally, stream must be associated with a device that has a non-zero value for the device attribute concurrentManagedAccess. Specifying musaMemLocationTypeHost as musaMemLocation::type will prefetch data to host memory. Applications can request prefetching memory to a specific host NUMA node by specifying musaMemLocationTypeHostNuma for musaMemLocation::type and a valid host NUMA node id in musaMemLocation::id Users can also request prefetching memory to the host NUMA node closest to the current thread's CPU by specifying musaMemLocationTypeHostNumaCurrent for musaMemLocation::type. Note when musaMemLocation::type is etiher musaMemLocationTypeHost OR musaMemLocationTypeHostNumaCurrent, musaMemLocation::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 musaMallocManaged allocations to host memory in order to make room. Device memory allocated using musaMalloc or musaMallocArray 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 musaMemAdviseSetReadMostly 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 musaMemAdviseSetPreferredLocation 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 musaMemAdviseSetAccessedBy 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(const void *): Pointer to be prefetchedcount(size_t): Size in byteslocation(struct musaMemLocation): location to prefetch toflags(unsigned int): flags for future use, must be zero now.stream(musaStream_t): Stream to enqueue prefetch operation
Returns
- musaSuccess, musaErrorInvalidValue, musaErrorInvalidDevice
Note
- This function may also return error codes from previous, asynchronous launches.
- This call may initialize internal runtime state and may also return initialization-related errors.
- No MUSA API may be called from a stream callback; a not-permitted error may be returned as a diagnostic.
- See the API synchronization behavior notes for asynchronous host/device behavior.
- See the default-stream note for NULL stream semantics.
See also
- musaMemcpy, musaMemcpyPeer, musaMemcpyAsync, musaMemcpy3DPeerAsync, musaMemAdvise, musaMemAdvise_v2 muMemPrefetchAsync