App Compatibility Handling

During application development, build in extensibility to facilitate forward compatibility (adaptation to new versions), or backward compatibility (support for older versions) when new applications need to run in legacy environments. The following methods can be used:

  • Runtime version detection: Obtain the version information when the program is started, and record logs or perform adaptation judgment.
    // Version-based conditional execution.
    int32_t versionNum;
    aclsysGetVersionNum("runtime", &versionNum);
    
    int32_t major = 8;
    int32_t minor = 5;
    
    if (versionNum >= major * 10000000 + minor * 100000) {
        // Use the new-version feature API.
        aclrtQueryEventStatus(event, &status);
    } else {
        // Use the legacy-compatible API.
        aclrtQueryEvent(event, &status);
    }
  • Feature capability query: Use the feature query API instead of the hardcoded version number for detection.
    // Query feature support.
    int32_t isSupported = 0;
    aclrtGetDevFeature(deviceId, ACL_FEATURE_TSCPU_TASK_UPDATE_SUPPORT_AIC_AIV, &isSupported);
    
    if (isSupported) {
        // Use the new feature for efficient implementation.
        useNewFeaturePath();
    } else {
        // Downgrade to compatible implementation.
        useLegacyPath();
    }