标签: simd

没有原始SIMD数据类型的基本原理

(对不起,如果这听起来像是一个咆哮,但这是一个真正的问题,我很欣赏真正的答案)

I understand that since C is so old, it might have not made sense to add it back then(MMX didn't even exist back then). But since then there was C99, and still there are no standard for SIMD variables(as far as I know).

By "SIMD variables", I mean something like:

vec2_int a = {2, 2};
vec2_int b = {3, 3};
a += b;
Run Code Online (Sandbox Code Playgroud)

I also understand that this can be done with structs and (in theory) the compiler should …

programming-languages language-design simd

2
推荐指数
1
解决办法
363
查看次数

多个Scala actor为一项任务提供服务

我需要并行处理多个数据值("SIMD").我可以使用java.util.concurrentAPI(Executors.newFixedThreadPool())使用Future实例以并行方式处理多个值:

import java.util.concurrent.{Executors, Callable}

class ExecutorsTest {
  private class Process(value: Int)
      extends Callable[Int] {
    def call(): Int = {
      // Do some time-consuming task
      value
    }
  }

  val executorService = {
    val threads = Runtime.getRuntime.availableProcessors
    Executors.newFixedThreadPool(threads)
  }

  val processes = for (process <- 1 to 1000) yield new Process(process)

  val futures = executorService.invokeAll(processes)

  // Wait for futures
}
Run Code Online (Sandbox Code Playgroud)

如何使用Actors做同样的事情?我不相信我想把所有进程"提供"给一个actor,因为actor会依次执行它们.

我是否需要使用"调度程序"actor创建多个"处理器"角色,该角色向每个"处理器"角色发送相同数量的进程?

concurrency scala simd actor

2
推荐指数
1
解决办法
920
查看次数

SSE对冲浮标练习

在处理SSE(AVX)中的整数和浮点数时,将所有整数转换为浮点数并仅使用浮点数是一个好习惯吗?因为之后我们只需要一些SIMD指令,而我们需要使用的是添加和比较指令(<, <=, ==),我希望这种转换应该完全保留.

c gcc sse simd avx

2
推荐指数
1
解决办法
1264
查看次数

使用DirectXMath中的XMVECTOR作为类成员仅在发布模式下导致崩溃?

我一直在尝试使用XMVECTOR作为边界框的类成员,因为我做了很多计算,但是每帧只使用一次XMFLOAT3,所以边界框有一个方法让我在XMFLOAT3中居中,否则它保留在XMVECTOR中;该类用__declspec(align(16))进行处理,并在调试模式下工作.但是在Release模式下,它崩溃了我设置的东西:

    Box& Box::operator=(const Box& box)
    {
        _center = box._center;
        _extents = box._extents;
        return *this;
    }
Run Code Online (Sandbox Code Playgroud)

每当我这样做:

Box A;

Box B;

A = B;
Run Code Online (Sandbox Code Playgroud)

它崩溃,给我0xC0000005:访问冲突读取位置0x00000000.当我将其创建为指针时,它也会崩溃:

Box* A = new Box();
Run Code Online (Sandbox Code Playgroud)

这是构造函数:

    Box::Box()
    {
        center = XMVectorZero();
        extents = XMVectorSplatOne();
    }
Run Code Online (Sandbox Code Playgroud)

再次,这在调试模式下工作正常,但在Release中它崩溃了.什么样的Release模式可以改变,会产生无效的代码?除了将盒子对齐到16个字节之外,我还需要做其他事情吗?

c++ simd release-mode directxmath

2
推荐指数
1
解决办法
1408
查看次数

c ++:表查找是否可以为小查找表进行矢量化

我想用SIMD内在函数来矢量化以下代码片段这可能吗?

unsigned char chain[3][3] = { 
            3,  2, 1,    //  y    --> x
            4, -1, 0,    //  | 
            5,  6, 7     //  |
            };           //  v    

std::vector<int> x;
std::vector<int> y;    
//initialize x, y

std::vector<int> chain_code(x.size());

for(std::size_t i = 0; i < x.size(); ++i
     chain_code[i] = chain[x[i]][y[i]];    
Run Code Online (Sandbox Code Playgroud)

编辑:

支持:SSE - SSE4.2和AVX

Architectur:Sandy Bridge i5 2500

c++ x86 sse simd avx

2
推荐指数
1
解决办法
1555
查看次数

优化元素2 ^ x-1的乘法

是否有任何已知的优化,用于乘以已知为2 ^ x-1(1,3,7 ......)的几个(3到5)字节(int8)

这是在使用(2 ^ x-1)/ 2 ^ x多次乘以字节数组的上下文中.除法是微不足道的(为右移添加指数),但分子有点麻烦.

此外,指数x仅在1..31中,并且所有的总和始终小于32.

// In reality there are 16 of these (i.e. a[16], b[16], c[16])
// ( a + b + c ) < 32
char  a = 2;
char  b = 16;
char  c = 8;

// Ratio/scale, there are 16 of these (i.e. r[16])
// It might work storing in log2 and using int8 or int16
// with fixed point approximation
<x?>  r = ( a - 1 ) * …
Run Code Online (Sandbox Code Playgroud)

c simd avx

2
推荐指数
1
解决办法
271
查看次数

_mm_store_si128抛出异常

所以我一直在尝试自己学习SEE优化,我不太了解它,我认为一个简单的函数只是将内存归零很容易实现,所以我继续尝试自己实现它.

这是零内存函数,它从缓冲区开始循环到缓冲区结束,并使用_mm_store_si128将其清零.

bool zeromem( byte * _dest, uint _sz )
{
    if ( _dest == nullptr )
        return false;
    __m128i zero = _mm_setzero_si128( );

    for ( auto i = rcast<__m128i*>( _dest ),
          end = rcast<__m128i*>( _dest + _sz );
          i < end; ++i )
    {
        _mm_store_si128( i, zero );
    }
    return true;
}
Run Code Online (Sandbox Code Playgroud)

抛出异常: 即使指针不是0x00000,也会发生访问冲突(0x00000).

我做的测试只是分配1024字节的内存,然后调用zeromem.

在第一次迭代时抛出异常.

c++ sse simd

2
推荐指数
1
解决办法
633
查看次数

使用SIMD/SSE进行水平运行差异和条件更新?

我想矢量化以下操作:

V[i+1] = max(V[i] - c, V[i+1]) for i=1 to n-1 (V[0] = 0)
Run Code Online (Sandbox Code Playgroud)

相应的天真伪代码是:

for (i=0; i < n; i++) {
  if (V[i]-c > V[i+1]) V[i+1] = V[i]-c
}
Run Code Online (Sandbox Code Playgroud)

哪些SIMD说明有用?

c c++ sse simd vectorization

2
推荐指数
1
解决办法
217
查看次数

对齐和SSE异常行为

我尝试与SSE合作,但遇到了一些奇怪的行为。

我编写了简单的代码,用于将两个字符串与SSE Intrinsics进行比较,然后运行它并起作用。但是后来我明白了,在我的代码中,指针之一仍然没有对齐,但是我使用了_mm_load_si128指令,它要求指针在16字节边界上对齐。

//Compare two different, not overlapping piece of memory
__attribute((target("avx"))) int is_equal(const void* src_1, const void* src_2, size_t size)
{
    //Skip tail for right alignment of pointer [head_1]
    const char* head_1 = (const char*)src_1;
    const char* head_2 = (const char*)src_2;
    size_t tail_n = 0;
    while (((uintptr_t)head_1 % 16) != 0 && tail_n < size)
    {                                
        if (*head_1 != *head_2)
            return 0;
        head_1++, head_2++, tail_n++;
    }

    //Vectorized part: check equality of memory with SSE4.1 instructions
    //src1 - …
Run Code Online (Sandbox Code Playgroud)

c c++ sse intel simd

2
推荐指数
1
解决办法
785
查看次数

带SIMD的矢量点积

我试图使用SIMD指令加速我的C代码中的点积计算.但是,我的函数的运行时间大致相等.如果有人能解释为什么以及如何加快计算,那就太棒了.

具体来说,我正在尝试计算两个数组的点积,其中包含大约10,000个元素.我的常规C函数如下:

 float my_dotProd( float const * const x, float const * const y, size_t const N ){
   // N is the number of elements in the arrays
   size_t i;
   float out=0;

   for( i=0; i < N; ++i ){
     out += x[i] * y[i];
   }

   return out;
 }
Run Code Online (Sandbox Code Playgroud)

我使用AVX SIMD命令的功能如下:

 void my_malloc( size_t nBytes, void ** ptrPtr ){
   int boundary = 32;
   posix_memalign( ptrPtr, boundary, nBytes );
 }

 float cimpl_sum_m128( __m128 x ){
   float out;
   __m128 sum = x;
   sum …
Run Code Online (Sandbox Code Playgroud)

c x86 simd avx

2
推荐指数
1
解决办法
2256
查看次数