在AVX-512加载和存储中使用掩码寄存器时,是否会由于对被掩码元素的无效访问而引发故障? [英] When using a mask register with AVX-512 load and stores, is a fault raised for invalid accesses to masked out elements?

查看:272
本文介绍了在AVX-512加载和存储中使用掩码寄存器时,是否会由于对被掩码元素的无效访问而引发故障?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我进行写屏蔽的AVX-512存储时,如下所示:

When I do a writemasked AVX-512 store, like so:

vmovdqu8 [rsi] {k1}, zmm0

如果未映射在<​​c>处访问的部分存储器,但是对于所有这些位置,写掩码为零(即,由于掩码而导致数据实际上未被修改),则会导致指令错误).

Will the instruction fault if some portion of the memory accessed at [rsi, rsi + 63] is not mapped but the writemask is zero for all those locations (i.e., the data is not actually modified due to the mask).

另一种询问方式是这些被AVX-512屏蔽的存储区是否具有与AVX中引入的vmaskmov类似的故障抑制能力.

Another way of asking it is if these AVX-512 masked stores have a similar fault suppression ability to vmaskmov introduced in AVX.

推荐答案

如果被掩盖的元素接触无效的内存,则不会引发任何错误.

No fault is raised if masked out elements touch invalid memory.

这里有一些Windows测试代码来证明屏蔽确实可以抑制内存错误.

Here's some Windows test code to prove that masking does indeed suppress memory faults.

#include <immintrin.h>
#include <iostream>
#include <Windows.h>
using namespace std; 


int main(){
    const size_t PAGE = 4096;

    //  Map 2 pages.
    char* ptr = (char*)VirtualAlloc(
        nullptr, 2*PAGE,
        MEM_COMMIT,
        PAGE_READWRITE
    );

    //  Store 64 bytes across page boundary.
    cout << "Store across page boundary." << endl;
    _mm512_storeu_si512(ptr + PAGE - 32, _mm512_set1_epi8(-1));

    //  Unmap top page.
    cout << "Unmap top page." << endl;
    VirtualFree(ptr + PAGE, PAGE, MEM_DECOMMIT);

    //  Write on boundary masking out the part that touches the top (unmapped page).
    //  Does not crash because bad accesses are masked out.
    cout << "Store across page boundary, but mask out bytes that are on unmapped page." << endl;
    _mm512_mask_storeu_epi8(ptr + PAGE - 32, 0x00000000ffffffff, _mm512_set1_epi8(-1));

    //  Store 64 bytes across page boundary.
    //  Crashes because of bad access.
    cout << "Store across page boundary." << endl;
    _mm512_storeu_si512(ptr + PAGE - 32, _mm512_set1_epi8(-1));

    cout << "Release bottom page." << endl;
    VirtualFree(ptr, 0, MEM_RELEASE);

    system("pause");
}

输出:

Store across page boundary.
Unmap top page.
Store across page boundary, but mask out bytes that are on unmapped page.
Store across page boundary.
**Access violation**

此测试的工作方式如下:

This test works as follows:

  1. 映射2个相邻页面.
  2. 在页面边界上进行AVX512存储以证明两个页面都已映射.
  3. 取消映射上部页面.
  4. 执行相同的AVX512存储,但屏蔽掉上部页面上的字节.它不会崩溃.
  5. 重复第一个AVX512存储(无遮罩).它崩溃了,从而证明了上层页面没有被映射,而屏蔽则抑制了崩溃.

这篇关于在AVX-512加载和存储中使用掩码寄存器时,是否会由于对被掩码元素的无效访问而引发故障?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆