Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
jerrrrry
infinicore
Commits
631cfd63
Commit
631cfd63
authored
Apr 09, 2025
by
PanZezhong
Browse files
issue/161/fix 修改检查shape strides相等的宏
parent
0450fb1e
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
25 deletions
+22
-25
src/infiniop/ops/causal_softmax/info.h
src/infiniop/ops/causal_softmax/info.h
+8
-14
src/infiniop/ops/swiglu/cpu/swiglu_cpu.cc
src/infiniop/ops/swiglu/cpu/swiglu_cpu.cc
+2
-3
src/utils/check.h
src/utils/check.h
+12
-8
No files found.
src/infiniop/ops/causal_softmax/info.h
View file @
631cfd63
...
@@ -31,32 +31,26 @@ public:
...
@@ -31,32 +31,26 @@ public:
}
}
CHECK_DTYPE
(
dtype
,
INFINI_DTYPE_F16
,
INFINI_DTYPE_F32
);
CHECK_DTYPE
(
dtype
,
INFINI_DTYPE_F16
,
INFINI_DTYPE_F32
);
auto
ndim
=
y_desc
->
ndim
();
auto
shape
=
y_desc
->
shape
();
if
(
ndim
!=
x_desc
->
ndim
())
{
CHECK_SAME_SHAPE
(
shape
,
x_desc
->
shape
());
return
INFINI_STATUS_BAD_TENSOR_SHAPE
;
}
auto
ndim
=
y_desc
->
ndim
();
if
(
ndim
!=
2
&&
ndim
!=
3
)
{
if
(
ndim
!=
2
&&
ndim
!=
3
)
{
return
INFINI_STATUS_BAD_TENSOR_SHAPE
;
CHECK_STATUS
(
INFINI_STATUS_BAD_TENSOR_SHAPE
);
}
auto
shape
=
y_desc
->
shape
();
if
(
!
SAME_VEC
(
y_desc
->
shape
(),
x_desc
->
shape
()))
{
return
INFINI_STATUS_BAD_TENSOR_SHAPE
;
}
}
if
(
shape
[
ndim
-
1
]
<
shape
[
ndim
-
2
])
{
if
(
shape
[
ndim
-
1
]
<
shape
[
ndim
-
2
])
{
return
INFINI_STATUS_BAD_TENSOR_SHAPE
;
CHECK_STATUS
(
INFINI_STATUS_BAD_TENSOR_SHAPE
)
;
}
}
size_t
batch_size
=
1
;
size_t
batch_size
=
1
;
size_t
seq_len
=
shape
[
ndim
-
2
];
size_t
seq_len
=
shape
[
ndim
-
2
];
size_t
total_seq_len
=
shape
[
ndim
-
1
];
size_t
total_seq_len
=
shape
[
ndim
-
1
];
ptrdiff_t
y_stride_b
=
0
,
ptrdiff_t
y_stride_b
=
0
,
x_stride_b
=
0
;
y_stride_i
=
y_desc
->
stride
(
ndim
-
2
),
ptrdiff_t
y_stride_i
=
y_desc
->
stride
(
ndim
-
2
),
y_stride_j
=
y_desc
->
stride
(
ndim
-
1
);
y_stride_j
=
y_desc
->
stride
(
ndim
-
1
);
ptrdiff_t
x_stride_i
=
x_desc
->
stride
(
ndim
-
2
),
ptrdiff_t
x_stride_b
=
0
,
x_stride_i
=
x_desc
->
stride
(
ndim
-
2
),
x_stride_j
=
x_desc
->
stride
(
ndim
-
1
);
x_stride_j
=
x_desc
->
stride
(
ndim
-
1
);
if
(
ndim
==
3
)
{
if
(
ndim
==
3
)
{
...
...
src/infiniop/ops/swiglu/cpu/swiglu_cpu.cc
View file @
631cfd63
...
@@ -18,9 +18,8 @@ infiniStatus_t Descriptor::create(
...
@@ -18,9 +18,8 @@ infiniStatus_t Descriptor::create(
const
auto
&
gate_shape
=
gate_desc
->
shape
();
const
auto
&
gate_shape
=
gate_desc
->
shape
();
CHECK_DTYPE
(
dtype
,
INFINI_DTYPE_F16
,
INFINI_DTYPE_F32
,
INFINI_DTYPE_F64
);
CHECK_DTYPE
(
dtype
,
INFINI_DTYPE_F16
,
INFINI_DTYPE_F32
,
INFINI_DTYPE_F64
);
if
(
!
SAME_VEC
(
out_shape
,
up_shape
,
gate_shape
))
{
return
INFINI_STATUS_BAD_TENSOR_SHAPE
;
CHECK_SAME_SHAPE
(
out_shape
,
up_shape
,
gate_shape
);
}
op
::
binary
::
BinaryInfo
info
;
op
::
binary
::
BinaryInfo
info
;
CHECK_STATUS
(
op
::
binary
::
createBinaryInfo
(
info
,
out_desc
,
up_desc
,
gate_desc
));
CHECK_STATUS
(
op
::
binary
::
createBinaryInfo
(
info
,
out_desc
,
up_desc
,
gate_desc
));
...
...
src/utils/check.h
View file @
631cfd63
...
@@ -31,13 +31,17 @@
...
@@ -31,13 +31,17 @@
return INFINI_STATUS_BAD_TENSOR_DTYPE); \
return INFINI_STATUS_BAD_TENSOR_DTYPE); \
} while (0)
} while (0)
#define SAME_VEC(...) \
#define CHECK_SAME_VEC(ERR, FIRST, ...) \
[&] { \
do { \
auto &&_vec = std::forward_as_tuple(__VA_ARGS__); \
for (const auto &shape___ : {__VA_ARGS__}) { \
const auto &_base = std::get<0>(_vec); \
if (FIRST != shape___) { \
return [&_base](auto &&...args) { \
return ERR; \
return ((args == _base) && ...); \
} \
}(__VA_ARGS__); \
} \
}()
} while (0)
#define CHECK_SAME_SHAPE(FIRST, ...) CHECK_SAME_VEC(INFINI_STATUS_BAD_TENSOR_SHAPE, FIRST, __VA_ARGS__)
#define CHECK_SAME_STRIDES(FIRST, ...) CHECK_SAME_VEC(INFINI_STATUS_BAD_TENSOR_STRIDES, FIRST, __VA_ARGS__)
#endif // INFINIUTILS_CHECK_H
#endif // INFINIUTILS_CHECK_H
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment