惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Forbes - Security
Forbes - Security
A
Arctic Wolf
M
MIT News - Artificial intelligence
T
Threat Research - Cisco Blogs
T
The Exploit Database - CXSecurity.com
C
CERT Recently Published Vulnerability Notes
NISL@THU
NISL@THU
L
Lohrmann on Cybersecurity
Martin Fowler
Martin Fowler
A
About on SuperTechFans
P
Palo Alto Networks Blog
Project Zero
Project Zero
The GitHub Blog
The GitHub Blog
WordPress大学
WordPress大学
Blog — PlanetScale
Blog — PlanetScale
博客园_首页
大猫的无限游戏
大猫的无限游戏
Cisco Talos Blog
Cisco Talos Blog
P
Proofpoint News Feed
D
DataBreaches.Net
Cyberwarzone
Cyberwarzone
T
Tor Project blog
IT之家
IT之家
P
Proofpoint News Feed
Help Net Security
Help Net Security
S
Securelist
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
C
CXSECURITY Database RSS Feed - CXSecurity.com
Microsoft Azure Blog
Microsoft Azure Blog
V2EX - 技术
V2EX - 技术
K
Kaspersky official blog
Hugging Face - Blog
Hugging Face - Blog
MongoDB | Blog
MongoDB | Blog
B
Blog
N
News and Events Feed by Topic
The Cloudflare Blog
S
Schneier on Security
P
Privacy & Cybersecurity Law Blog
T
The Blog of Author Tim Ferriss
Recorded Future
Recorded Future
Last Week in AI
Last Week in AI
The Last Watchdog
The Last Watchdog
Hacker News - Newest:
Hacker News - Newest: "LLM"
L
LangChain Blog
I
InfoQ
F
Full Disclosure
The Register - Security
The Register - Security
阮一峰的网络日志
阮一峰的网络日志
H
Hacker News: Front Page
V
V2EX

博客园 - Charltsing

C# 预处理器指令语言 - 完整语法速查 LoggerMessage:编写高性能的 .NET 日志 PDFImageViewer v2.1 PDF查看图像和无损导出工具,一键转换单图PDF为JBig2黑白PDF。兼谈PDF内嵌图像。 PDF的色彩空间 25 个使用.NET 10 的性能技巧 PDFontFixer v1.5 免费版,解决PDF文档复制粘贴乱码的问题,修复PDF文档字体的Unicode映射。 为什么 PDF 编辑这么难? Unicode、UTF-8、UTF-16 如何直接编辑Github的Readme.md文件 自动导入工程项目属性,Directory.Build.props 和 Directory.Build.targets 新版 C# 高效率编程指南 C# 内联数组(Inline Array):高性能数组的新选择 如何在 .NET 中使用 SIMD .NET异步编程进阶:从语法糖到高性能架构的核心突破 C# 中的安全零拷贝 使用UnsafeAccessor 访问私有字段 C# 12与.NET 8实战指南:20个提升代码质量的最佳实践 C# Net9的模块初始化器(Module Initializer) ECMA-335 CLI 规范附录 C#中避免GC压力和提高性能的8种技术 函数内联 官方:oPDF v2.1免费版,专业的PDF水印分析处理工具,无损去除水印,通杀八类PDF水印。它是PDFCommander 万能PDF水印删除工具的升级版。 C#自动引用Debug | Release版本的dll
硬件内在函数
Charltsing · 2025-09-12 · via 博客园 - Charltsing

AVX-512支持:SIMD的终极形态

// 优化的数值计算// 优化前的代码
public double[] ProcessData(double[] input)
{
    var result = new double[input.Length];
    for (int i = 0; i < input.Length; i++)
    {
        result[i] = Math.Sin(input[i]) * Math.Cos(input[i]);
    }
    return result;
}

// 优化后的代码:使用硬件内在函数
public unsafe double[] ProcessDataOptimized(double[] input)
{
    var result = new double[input.Length];
    
    fixed (double* pInput = input, pResult = result)
    {
        int i = 0;
        if (Avx512F.IsSupported)
        {
            var size = Vector512<double>.Count;
            for (; i <= input.Length - size; i += size)
            {
                var vec = Avx512F.LoadVector512(pInput + i);
                var sinVec = Avx512F.Sin(vec);
                var cosVec = Avx512F.Cos(vec);
                var product = Avx512F.Multiply(sinVec, cosVec);
                Avx512F.Store(pResult + i, product);
            }
        }
        
        // 处理剩余元素
        for (; i < input.Length; i++)
        {
            pResult[i] = Math.Sin(pInput[i]) * Math.Cos(pInput[i]);
        }
    }
    
    return result;
}


//使用AVX-512进行高性能矩阵运算
using System.Runtime.Intrinsics;
using System.Runtime.Intrinsics.X86;

public unsafe void MatrixMultiply(float* left, float* right, float* result, int size)
{
    for (int i = 0; i < size; i++)
    {
        for (int j = 0; j < size; j += 16) // 一次处理16个单精度浮点数
        {
            // 加载16个float到AVX-512寄存器
            var vecLeft = Avx512F.LoadVector512(left + i * size + j);
            var vecRight = Avx512F.LoadVector512(right + j * size);
            
            // 执行向量乘法
            var product = Avx512F.Multiply(vecLeft, vecRight);
            
            // 存储结果
            Avx512F.Store(result + i * size + j, product);
        }
    }
}
public void OptimizedMethod()
{
    if (Avx512F.IsSupported)
    {
        // 使用AVX-512优化
        ProcessWithAvx512();
    }
    else if (Avx2.IsSupported)
    {
        // 使用AVX2优化
        ProcessWithAvx2();
    }
    else if (Sse42.IsSupported)
    {
        // 使用SSE4.2优化
        ProcessWithSse42();
    }
    else
    {
        // 回退到标量实现
        ProcessScalar();
    }
}