Skip to content

Commit f0da8e4

Browse files
ericcanosmuzaffar
authored andcommitted
Pushed resize choice to compile time to avoid warnings in CUDA
1 parent 4afd37a commit f0da8e4

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

Eigen/src/LU/InverseImpl.h

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -293,10 +293,28 @@ struct Assignment<DstXprType, Inverse<XprType>, internal::assign_op<typename Dst
293293
EIGEN_DEVICE_FUNC
294294
static void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op<typename DstXprType::Scalar,typename XprType::Scalar> &)
295295
{
296-
Index dstRows = src.rows();
297-
Index dstCols = src.cols();
298-
if((dst.rows()!=dstRows) || (dst.cols()!=dstCols))
299-
dst.resize(dstRows, dstCols);
296+
#if(__cplusplus >= 201703L) // Do we have C++17 ?
297+
// Check the storage type at compile time and do not allow resizing fixed sizes (in case of size mismatch).
298+
// This will prevent pushing calls for host only resize() in cuda kernels (and avoid computations at runtime
299+
// with fixed sizes)
300+
if constexpr (Eigen::internal::traits< XprType >::MaxRowsAtCompileTime == Eigen::Dynamic
301+
|| Eigen::internal::traits< XprType >::MaxColsAtCompileTime == Eigen::Dynamic
302+
|| Eigen::internal::traits< DstXprType >::MaxRowsAtCompileTime == Eigen::Dynamic
303+
|| Eigen::internal::traits< DstXprType >::MaxColsAtCompileTime == Eigen::Dynamic) {
304+
#endif // C++17
305+
Index dstRows = src.rows();
306+
Index dstCols = src.cols();
307+
if((dst.rows()!=dstRows) || (dst.cols()!=dstCols))
308+
dst.resize(dstRows, dstCols);
309+
#if(__cplusplus >= 201703L) // Do we have C++17 ?
310+
} else {
311+
constexpr Index srcRows = Eigen::internal::traits< XprType >::RowsAtCompileTime;
312+
constexpr Index srcCols = Eigen::internal::traits< XprType >::ColsAtCompileTime;
313+
constexpr Index dstRows = Eigen::internal::traits< DstXprType >::RowsAtCompileTime;
314+
constexpr Index dstCols = Eigen::internal::traits< DstXprType >::ColsAtCompileTime;
315+
EIGEN_STATIC_ASSERT(((dstRows==srcRows) && (dstCols==srcCols)), YOU_MIXED_MATRICES_OF_DIFFERENT_SIZES);
316+
}
317+
#endif // C++17
300318

301319
const int Size = EIGEN_PLAIN_ENUM_MIN(XprType::ColsAtCompileTime,DstXprType::ColsAtCompileTime);
302320
EIGEN_ONLY_USED_FOR_DEBUG(Size);

0 commit comments

Comments
 (0)