Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
187 changes: 186 additions & 1 deletion sycl/include/sycl/ext/oneapi/matrix/matrix-jit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,16 @@ class wi_element {
PI_INVALID_DEVICE);
#endif // __SYCL_DEVICE_ONLY__
}

explicit operator bool() {
#ifdef __SYCL_DEVICE_ONLY__
return __spirv_VectorExtractDynamic(M.spvm, idx) != static_cast<T>(0);
#else
throw runtime_error("joint matrix is not supported on host device.",
PI_INVALID_DEVICE);
#endif // __SYCL_DEVICE_ONLY__
}

wi_element &operator=(const T &rhs) {
#ifdef __SYCL_DEVICE_ONLY__
M.spvm = __spirv_VectorInsertDynamic(M.spvm, rhs, idx);
Expand All @@ -248,6 +258,80 @@ class wi_element {
PI_INVALID_DEVICE);
#endif // __SYCL_DEVICE_ONLY__
}

wi_element &
operator=(const wi_element<T, NumRows, NumCols, Layout, Group> &rhs) {
#ifdef __SYCL_DEVICE_ONLY__
M.spvm = __spirv_VectorInsertDynamic(
M.spvm, __spirv_VectorExtractDynamic(rhs.M.spvm, rhs.idx), idx);
return *this;
#else
(void)rhs;
throw runtime_error("joint matrix is not supported on host device.",
PI_INVALID_DEVICE);
#endif // __SYCL_DEVICE_ONLY__
}

friend T operator+(const wi_element<T, NumRows, NumCols, Layout, Group> &lhs,
const T &rhs) {
#ifdef __SYCL_DEVICE_ONLY__
return __spirv_VectorExtractDynamic(lhs.M.spvm, lhs.idx) + rhs;
#else
(void)lhs;
(void)rhs;
throw runtime_error("joint matrix is not supported on host device.",
PI_INVALID_DEVICE);
#endif // __SYCL_DEVICE_ONLY__
}

wi_element &operator+=(const T &rhs) {
#ifdef __SYCL_DEVICE_ONLY__
M.spvm = __spirv_VectorInsertDynamic(
M.spvm, __spirv_VectorExtractDynamic(M.spvm, idx) + rhs, idx);
return *this;
#else
(void)rhs;
throw runtime_error("joint matrix is not supported on host device.",
PI_INVALID_DEVICE);
#endif // __SYCL_DEVICE_ONLY__
}

friend T operator-(const wi_element<T, NumRows, NumCols, Layout, Group> &lhs,
const T &rhs) {
#ifdef __SYCL_DEVICE_ONLY__
return __spirv_VectorExtractDynamic(lhs.M.spvm, lhs.idx) - rhs;
#else
(void)lhs;
(void)rhs;
throw runtime_error("joint matrix is not supported on host device.",
PI_INVALID_DEVICE);
#endif // __SYCL_DEVICE_ONLY__
}

wi_element &operator-=(const T &rhs) {
#ifdef __SYCL_DEVICE_ONLY__
M.spvm = __spirv_VectorInsertDynamic(
M.spvm, __spirv_VectorExtractDynamic(M.spvm, idx) - rhs, idx);
return *this;
#else
(void)rhs;
throw runtime_error("joint matrix is not supported on host device.",
PI_INVALID_DEVICE);
#endif // __SYCL_DEVICE_ONLY__
}

friend T operator*(const wi_element<T, NumRows, NumCols, Layout, Group> &lhs,
const T &rhs) {
#ifdef __SYCL_DEVICE_ONLY__
return __spirv_VectorExtractDynamic(lhs.M.spvm, lhs.idx) * rhs;
#else
(void)lhs;
(void)rhs;
throw runtime_error("joint matrix is not supported on host device.",
PI_INVALID_DEVICE);
#endif // __SYCL_DEVICE_ONLY__
}

wi_element &operator*=(const T &rhs) {
#ifdef __SYCL_DEVICE_ONLY__
M.spvm = __spirv_VectorInsertDynamic(
Expand All @@ -259,7 +343,108 @@ class wi_element {
PI_INVALID_DEVICE);
#endif // __SYCL_DEVICE_ONLY__
}
// TODO: add other arithmetic operators

friend T operator/(const wi_element<T, NumRows, NumCols, Layout, Group> &lhs,
const T &rhs) {
#ifdef __SYCL_DEVICE_ONLY__
return __spirv_VectorExtractDynamic(lhs.M.spvm, lhs.idx) / rhs;
#else
(void)lhs;
(void)rhs;
throw runtime_error("joint matrix is not supported on host device.",
PI_INVALID_DEVICE);
#endif // __SYCL_DEVICE_ONLY__
}

wi_element &operator/=(const T &rhs) {
#ifdef __SYCL_DEVICE_ONLY__
M.spvm = __spirv_VectorInsertDynamic(
M.spvm, __spirv_VectorExtractDynamic(M.spvm, idx) / rhs, idx);
return *this;
#else
(void)rhs;
throw runtime_error("joint matrix is not supported on host device.",
PI_INVALID_DEVICE);
#endif // __SYCL_DEVICE_ONLY__
}

friend bool
operator<(const wi_element<T, NumRows, NumCols, Layout, Group> &lhs,
const T &rhs) {
#ifdef __SYCL_DEVICE_ONLY__
return __spirv_VectorExtractDynamic(lhs.M.spvm, lhs.idx) < rhs;
#else
(void)lhs;
(void)rhs;
throw runtime_error("joint matrix is not supported on host device.",
PI_INVALID_DEVICE);
#endif // __SYCL_DEVICE_ONLY__
}

friend bool
operator<=(const wi_element<T, NumRows, NumCols, Layout, Group> &lhs,
const T &rhs) {
#ifdef __SYCL_DEVICE_ONLY__
return __spirv_VectorExtractDynamic(lhs.M.spvm, lhs.idx) <= rhs;
#else
(void)lhs;
(void)rhs;
throw runtime_error("joint matrix is not supported on host device.",
PI_INVALID_DEVICE);
#endif // __SYCL_DEVICE_ONLY__
}

friend bool
operator>(const wi_element<T, NumRows, NumCols, Layout, Group> &lhs,
const T &rhs) {
#ifdef __SYCL_DEVICE_ONLY__
return __spirv_VectorExtractDynamic(lhs.M.spvm, lhs.idx) > rhs;
#else
(void)lhs;
(void)rhs;
throw runtime_error("joint matrix is not supported on host device.",
PI_INVALID_DEVICE);
#endif // __SYCL_DEVICE_ONLY__
}

friend bool
operator>=(const wi_element<T, NumRows, NumCols, Layout, Group> &lhs,
const T &rhs) {
#ifdef __SYCL_DEVICE_ONLY__
return __spirv_VectorExtractDynamic(lhs.M.spvm, lhs.idx) >= rhs;
#else
(void)lhs;
(void)rhs;
throw runtime_error("joint matrix is not supported on host device.",
PI_INVALID_DEVICE);
#endif // __SYCL_DEVICE_ONLY__
}

friend bool
operator==(const wi_element<T, NumRows, NumCols, Layout, Group> &lhs,
const T &rhs) {
#ifdef __SYCL_DEVICE_ONLY__
return __spirv_VectorExtractDynamic(lhs.M.spvm, lhs.idx) == rhs;
#else
(void)lhs;
(void)rhs;
throw runtime_error("joint matrix is not supported on host device.",
PI_INVALID_DEVICE);
#endif // __SYCL_DEVICE_ONLY__
}

friend bool
operator!=(const wi_element<T, NumRows, NumCols, Layout, Group> &lhs,
const T &rhs) {
#ifdef __SYCL_DEVICE_ONLY__
return __spirv_VectorExtractDynamic(lhs.M.spvm, lhs.idx) != rhs;
#else
(void)lhs;
(void)rhs;
throw runtime_error("joint matrix is not supported on host device.",
PI_INVALID_DEVICE);
#endif // __SYCL_DEVICE_ONLY__
}
};

template <typename T, size_t NumRows, size_t NumCols, matrix_layout Layout,
Expand Down