【翻译】(9)CPU Features

介绍了Android NDK提供的cpufeatures库,该库可用于运行时检测目标设备的CPU家族及支持的特性。支持ARM家族,并提供了检测ARMv7指令集、VFPv3 FPU扩展及NEON向量指令集的功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

-----------------

英文文档见android-ndk-r5b的documentation.html

属于Android Native Development Kit (NDK)的一部分

见http://developer.android.com/sdk/ndk/(需要代理)

翻译仅个人见解

-----------------

 

Android NDK CPU Features detection library:

 

Android NDK CPU特性检测库:

-------------------------------------------

 

This NDK provides a small library named "cpufeatures" that can be used at runtime to detect the target device's CPU family and the optional features it supports.

 

NDK提供一个名为cpufeatures的小型库,它可以用于在运行期检测目标设备的CPU家族和它支持的可选特性。

 

Usage:

 

用法:

------

 

The library is available as an import module. To use it, you must:

 

这个库作为导入模块可用。要使用它,你必须:

 

To use it, you must:

 

要使用它,你必须:

 

  * List 'cpufeatures' in your list of static library dependencies, as in:

 

  * 在你的静态库依赖列表中列出cpufeatures,正如这样:

 

        LOCAL_STATIC_LIBRARIES := cpufeatures

 

  * At the end of your Android.mk, import the 'android/cpufeatures' module, as in:

 

  * 在你的Android.mk结束处,导入android/cpufeatures模块,正如这样:

 

        $(call import-module,android/cpufeatures)

 

  * In your source code, include the header named <cpu-features.h>

 

  * 在你的源代码中,包含名为<cpu-features.h>的头文件

 

Here is a simple example:

 

这里是一个简单示例:

 

<project-path>/jni/Android.mk:

    LOCAL_PATH := $(call my-dir)

 

    include $(CLEAR_VARS)

    LOCAL_MODULE := <your-module-name>

    LOCAL_SRC_FILES := <your-source-files>

    LOCAL_STATIC_LIBRARIES := cpufeatures

    include $(BUILD_SHARED_LIBRARY)

 

    $(call import-module,android/cpufeatures)

 

 

Features:

 

特性:

---------

 

Two functions are provided for now:

 

现在提供两个函数:

 

   AndroidCpuFamily   android_getCpuFamily();

 

Returns the target device's CPU Family as an enum. For now, the only supported family is ANDROID_CPU_FAMILY_ARM.

 

用一个枚举值返回目标设备的CPU家族。现在,唯一支持的家族是ANDROID_CPU_FAMILY_ARM。

 

   uint64_t   android_getCpuFeatures();

 

Returns the set of optional features supported by the device's CPU. The result is a set of bit-flags, each corresponding to one CPU Family-specific optional feature.

 

返回设备CPU支持的可选特性。结构是一个位标志集合,每个位标志对应一项CPU家族特定的可选特性。

 

Currently, only the following flags are defined, for the ARM CPU Family:

 

目前,只为ARM CPU家族定义了如下标志:

 

   ANDROID_CPU_ARM_FEATURE_ARMv7

      Indicates that the device's CPU supports the ARMv7-A instruction set as supported by the "armeabi-v7a" abi (see CPU-ARCH-ABIS.html). This corresponds to Thumb-2 and VFPv3-D16 instructions.

 

   ANDROID_CPU_ARM_FEATURE_ARMv7

      指出设备的CPU支持ARMv7-A指令集,它由armeabi-v7a的ABI(注:应用程序二进制接口,操作系统暴露的接口,使二进制程序不需要重新编译即可在兼容ABI的操作系统上运行)支持(参考CPU-ARCH-ABIS.html)。它对应Thumb-2和VFPv3-D16指令。

 

 

   ANDROID_CPU_ARM_FEATURE_VFPv3

      Indicates that the device's CPU supports the VFPv3 hardware FPU instruction set extension. Due to the definition of 'armeabi-v7a', this will always be the case if ANDROID_CPU_ARM_FEATURE_ARMv7 is returned.

 

   ANDROID_CPU_ARM_FEATURE_VFPv3

      指出设备CPU支持VFPv3硬件FPU(注:FPU是浮点运算单元的缩写)指令集扩展。由于armeabi-v7a的定义,它将总是返回ANDROID_CPU_ARM_FEATURE_ARMv7(注:这里的意思可能是,它总是和ANDROID_CPU_ARM_FEATURE_ARMv7一起返回)。

 

      Note that this corresponds to the minimum profile VFPv3-D16 that _only_ provides 16 hardware FP registers.

 

 注意它对应最小型号是VFPv3-D16,它只提供16个硬件浮点寄存器。

 

   ANDROID_CPU_ARM_FEATURE_NEON

      Indicates that the device's CPU supports the ARM Advanced SIMD (a.k.a. NEON) vector instruction set extension. Note that ARM mandates that such CPUs also implement VFPv3-D32, which provides 32 hardware FP registers (shared with the NEON unit).

 

   ANDROID_CPU_ARM_FEATURE_NEON

      指出设备CPU支持ARM高级SIMD(即NEON)(注:NEON技术是ARM SIMD扩展指令,用于多媒体处理的硬件加速)向量指令集扩展。注意ARM授权这种CPU还实现了VFPv3-D32,提供32个硬件浮点寄存器(与NEON单元共享)。

 

 

Important Note:

 

重要注意事项:

---------------

 

The cpufeatures library will be updated to support more CPU families and optional features in the future. It is designed to work as-is on all official Android platform versions.

 

cpufeatures库将被更新以支持未来更多CPU家族和可选特性。它被设计为在所有官方Android平台版本上保持原样地工作。

 

Change History:

 

修改历史:

---------------

 

Please see the comments in $NDK/sources/android/cpufeatures/cpu-features.c for the complete change history for this library.

 

请参考$NDK/sources/android/cpufeatures/cpu-features.c中的注释以获得这个库的完整修改历史。(注:估计写文档的人太懒...)

 

### DehazeNet 中文翻译及去雾网络介绍 #### 一、DehazeNet简介 DehazeNet是一种专门用于图像去雾的卷积神经网络模型。该网络旨在解决由大气散射效应引起的照片或视频中的视觉退化问题,提升图像清晰度并恢复场景的真实色彩[^1]。 #### 二、工作原理概述 为了有效去除雾霾影响,DehazeNet采用了端到端的学习框架,在输入一张含雾图片后可以直接输出对应的无雾版本。具体来说,此方法利用了暗通道先验理论作为指导原则之一,并结合深度学习技术自动提取特征,进而估计透射率图谱,最终实现高质量的复原效果。 #### 三、应用场景举例 对于自动驾驶汽车而言,良好的视线至关重要;而在恶劣天气条件下(如下雨天或者有浓重烟尘),摄像头捕捉的画面往往会受到一定程度的影响。此时应用像DehazeNet这样的先进算法可以帮助改善感知系统的性能,确保行车安全。另外,在无人机航拍领域同样可以发挥重要作用,使得拍摄出来的影像更加逼真自然[^2]。 ```python import torch from torchvision import models, transforms from PIL import Image def load_image(image_path): preprocess = transforms.Compose([ transforms.Resize((224, 224)), transforms.ToTensor(), ]) image = Image.open(image_path).convert(&#39;RGB&#39;) return preprocess(image).unsqueeze(0) # 加载预训练好的dehazenet模型权重文件 model_weights = &#39;path_to_dehaze_net.pth&#39; device = torch.device("cuda" if torch.cuda.is_available() else "cpu") net = models.resnet50(pretrained=False) num_ftrs = net.fc.in_features net.fc = nn.Linear(num_ftrs, 3) # 输出三个通道(RGB) net.load_state_dict(torch.load(model_weights)) net.to(device); net.eval(); input_tensor = load_image(&#39;foggy_scene.jpg&#39;).to(device) with torch.no_grad(): output_tensor = net(input_tensor) clear_image = transforms.ToPILImage()(output_tensor.squeeze().cpu()) clear_image.show() ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值