Skip to content

Eigen::SkewSymmetricMatrix3 not working in CUDA kernel code

Summary

SkewSymmetricMatrix3 wrapper doesn't work inside CUDA kernels / outputs only zeros when converted to dense matrix form.

Environment

  • Operating System : Linux
  • Architecture : x64
  • Eigen Version : before-3.4-608-g67286839 / commit hash 67286839
  • Compiler Version : Gcc 11.3.0
  • Compile Flags : -g -fdiagnostics-color=always -std=gnu++17 -fsyntax-only
  • Vector Extension : SSE4.1, SSE4.2, SSE4A, full list here (this is irrelevant for this bug)

Minimal Example

After checking result on the CPU, please place the following code inside a CUDA kernel:

Eigen::Vector3f axis;
axis << 0.158371, 0.78828, 0.594587;
Eigen::SkewSymmetricMatrix3<float> axis_skew(axis);
Eigen::Matrix3<TElement> axis_skew_dense = axis_skew.toDenseMatrix();
printf("%f %f %f\n"
       "%f %f %f\n"
       "%f %f %f\n",
	axis_skew_dense(0,0), axis_skew_dense(0,1), axis_skew_dense(0,2),
	axis_skew_dense(1,0), axis_skew_dense(1,1), axis_skew_dense(1,2),
	axis_skew_dense(2,0), axis_skew_dense(2,1), axis_skew_dense(2,2));

Steps to reproduce

  1. Run the above code on a CPU.
  2. Run the above code inside a CUDA kernel.
  3. Compare the results.

What is the current bug behavior?

You will get all-zero output:

0.000000 0.000000 0.000000
0.000000 0.000000 0.000000
0.000000 0.000000 0.000000

What is the expected correct behavior?

The correct (CPU) output is:

0.000000 -0.594587 0.788280
0.594587 0.000000 -0.158371
-0.788280 0.158371 0.000000