aclrtGetSymbolAddress
Applicable Products
Product |
Supported |
|---|---|
√ |
|
√ |
|
√ |
|
☓ |
|
√ |
|
☓ |
Function
Obtains the address of a device variable.
This is an encapsulated API that applies only to C++ programs. It internally calls the C API aclrtGetSymbolAddress.
Prototype
1 2 | template <typename T> aclError aclrtGetSymbolAddress(const T &symbol, void **devPtr) |
Parameters
Parameter |
Input/Output |
Description |
|---|---|---|
symbol |
Input |
Device variable. The device variable is declared with __gm__. |
devPtr |
Output |
Pointer to the device memory address associated with the symbol. |
Returns
0 on success; otherwise, failure. For details, see aclError.
Restrictions
- This API is used only when a custom operator is developed using the Ascend C language and the host and device code is compiled together using the BiSheng compiler.
- The device variable address is valid only for the current device. After the device is switched, you need to obtain the address again.
- Only device variables in AI Core operators are supported. The specific restrictions are as follows:
- Only device variables (for example, __gm__ float convWeights) defined in the file where the main function is located are supported.
- Device variables can be referenced across files using the extern keyword. For example, if __gm__ float convWeights is defined in file A, it can be declared and referenced in file B using extern __gm__ float convWeights. The compilation requirements must be met: Use the -dc mode of the BiSheng compiler to compile multiple source files into one operator binary file.
- Basic data types, function pointers, structures, and arrays are supported. The class type is not supported. Note that function pointers can only point to pure scalar functions and cannot effectively distinguish between Cube and Vector function logic.
Parent topic: C++ Extension APIs