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
03edef48
You need to sign in or sign up before continuing.
Commit
03edef48
authored
Apr 24, 2025
by
Graylatzhou
Browse files
issue/183 Mul算子CPU&CUDA
parent
9e5d4eba
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
27 deletions
+24
-27
include/infiniop.h
include/infiniop.h
+1
-1
test/infiniop-test/test_generate/testcases/mul.py
test/infiniop-test/test_generate/testcases/mul.py
+21
-25
test/infiniop/mul.py
test/infiniop/mul.py
+2
-1
No files found.
include/infiniop.h
View file @
03edef48
...
@@ -12,6 +12,7 @@
...
@@ -12,6 +12,7 @@
#include "infiniop/ops/global_avg_pool.h"
#include "infiniop/ops/global_avg_pool.h"
#include "infiniop/ops/max_pool.h"
#include "infiniop/ops/max_pool.h"
#include "infiniop/ops/mlp.h"
#include "infiniop/ops/mlp.h"
#include "infiniop/ops/mul.h"
#include "infiniop/ops/random_sample.h"
#include "infiniop/ops/random_sample.h"
#include "infiniop/ops/rearrange.h"
#include "infiniop/ops/rearrange.h"
#include "infiniop/ops/relu.h"
#include "infiniop/ops/relu.h"
...
@@ -19,6 +20,5 @@
...
@@ -19,6 +20,5 @@
#include "infiniop/ops/rope.h"
#include "infiniop/ops/rope.h"
#include "infiniop/ops/swiglu.h"
#include "infiniop/ops/swiglu.h"
#include "infiniop/tensor_descriptor.h"
#include "infiniop/tensor_descriptor.h"
#include "infiniop/ops/mul.h"
#endif // __INFINIOP_API_H__
#endif // __INFINIOP_API_H__
test/infiniop-test/test_generate/testcases/mul.py
View file @
03edef48
...
@@ -6,12 +6,9 @@ from .. import InfiniopTestWriter, InfiniopTestCase, np_dtype_to_ggml, gguf_stri
...
@@ -6,12 +6,9 @@ from .. import InfiniopTestWriter, InfiniopTestCase, np_dtype_to_ggml, gguf_stri
def
mul
(
def
mul
(
a
:
np
.
ndarray
,
a
:
np
.
ndarray
,
b
:
np
.
ndarray
,
b
:
np
.
ndarray
c
:
np
.
ndarray
=
None
,
):
):
if
c
is
None
:
return
np
.
multiply
(
a
,
b
)
return
np
.
multiply
(
a
,
b
)
return
np
.
multiply
(
a
,
b
,
out
=
c
)
def
random_tensor
(
shape
,
dtype
):
def
random_tensor
(
shape
,
dtype
):
rate
=
1e-3
rate
=
1e-3
...
@@ -56,7 +53,7 @@ class MulTestCase(InfiniopTestCase):
...
@@ -56,7 +53,7 @@ class MulTestCase(InfiniopTestCase):
a_fp64
=
self
.
a
.
astype
(
np
.
float64
)
a_fp64
=
self
.
a
.
astype
(
np
.
float64
)
b_fp64
=
self
.
b
.
astype
(
np
.
float64
)
b_fp64
=
self
.
b
.
astype
(
np
.
float64
)
ans_fp64
=
np
.
multiply
(
a_fp64
,
b_fp64
)
ans_fp64
=
np
.
multiply
(
a_fp64
,
b_fp64
)
ans
=
mul
(
self
.
a
,
self
.
b
,
self
.
c
)
ans
=
mul
(
self
.
a
,
self
.
b
)
test_writer
.
add_tensor
(
test_writer
.
add_tensor
(
test_writer
.
gguf_key
(
"ans"
),
ans
,
raw_dtype
=
np_dtype_to_ggml
(
ans
.
dtype
)
test_writer
.
gguf_key
(
"ans"
),
ans
,
raw_dtype
=
np_dtype_to_ggml
(
ans
.
dtype
)
)
)
...
@@ -73,17 +70,17 @@ if __name__ == '__main__':
...
@@ -73,17 +70,17 @@ if __name__ == '__main__':
random_tensor
((
2
,
3
),
np
.
float32
),
random_tensor
((
2
,
3
),
np
.
float32
),
gguf_strides
(
3
,
1
),
gguf_strides
(
3
,
1
),
random_tensor
((
2
,
3
),
np
.
float32
),
random_tensor
((
2
,
3
),
np
.
float32
),
(
1
,
2
),
gguf_strides
(
1
,
2
),
random_tensor
((
2
,
3
),
np
.
float32
),
random_tensor
((
2
,
3
),
np
.
float32
),
gguf_strides
(
3
,
1
),
gguf_strides
(
3
,
1
),
),
),
MulTestCase
(
MulTestCase
(
random_tensor
((
2
,
3
),
np
.
float16
),
random_tensor
((
2
,
3
),
np
.
float16
),
(
1
,
2
),
gguf_strides
(
1
,
2
),
random_tensor
((
2
,
3
),
np
.
float16
),
random_tensor
((
2
,
3
),
np
.
float16
),
gguf_strides
(
3
,
1
),
gguf_strides
(
3
,
1
),
random_tensor
((
2
,
3
),
np
.
float16
),
random_tensor
((
2
,
3
),
np
.
float16
),
(
1
,
2
),
gguf_strides
(
1
,
2
),
),
),
MulTestCase
(
MulTestCase
(
random_tensor
((
2
,
3
),
np
.
float64
),
random_tensor
((
2
,
3
),
np
.
float64
),
...
@@ -91,7 +88,7 @@ if __name__ == '__main__':
...
@@ -91,7 +88,7 @@ if __name__ == '__main__':
random_tensor
((
2
,
3
),
np
.
float64
),
random_tensor
((
2
,
3
),
np
.
float64
),
gguf_strides
(
3
,
1
),
gguf_strides
(
3
,
1
),
random_tensor
((
2
,
3
),
np
.
float64
),
random_tensor
((
2
,
3
),
np
.
float64
),
(
1
,
2
),
gguf_strides
(
1
,
2
),
),
),
MulTestCase
(
MulTestCase
(
random_tensor
((
4
,
6
),
np
.
float16
),
random_tensor
((
4
,
6
),
np
.
float16
),
...
@@ -103,49 +100,49 @@ if __name__ == '__main__':
...
@@ -103,49 +100,49 @@ if __name__ == '__main__':
),
),
MulTestCase
(
MulTestCase
(
random_tensor
((
1
,
2048
),
np
.
float16
),
random_tensor
((
1
,
2048
),
np
.
float16
),
(
1
,
1
),
gguf_strides
(
1
,
1
),
random_tensor
((
1
,
2048
),
np
.
float16
),
random_tensor
((
1
,
2048
),
np
.
float16
),
gguf_strides
(
2048
,
1
),
gguf_strides
(
2048
,
1
),
random_tensor
((
1
,
2048
),
np
.
float16
),
random_tensor
((
1
,
2048
),
np
.
float16
),
(
1
,
1
),
gguf_strides
(
1
,
1
),
),
),
MulTestCase
(
MulTestCase
(
random_tensor
((
2048
,
2048
),
np
.
float32
),
random_tensor
((
2048
,
2048
),
np
.
float32
),
None
,
None
,
random_tensor
((
2048
,
2048
),
np
.
float32
),
random_tensor
((
2048
,
2048
),
np
.
float32
),
(
1
,
2048
),
gguf_strides
(
1
,
2048
),
random_tensor
((
2048
,
2048
),
np
.
float32
),
random_tensor
((
2048
,
2048
),
np
.
float32
),
None
,
None
,
),
),
MulTestCase
(
MulTestCase
(
random_tensor
((
2
,
4
,
2048
),
np
.
float16
),
random_tensor
((
2
,
4
,
2048
),
np
.
float16
),
(
4
*
2048
,
2048
,
1
),
gguf_strides
(
4
*
2048
,
2048
,
1
),
random_tensor
((
2
,
4
,
2048
),
np
.
float16
),
random_tensor
((
2
,
4
,
2048
),
np
.
float16
),
(
1
,
2
,
2
*
4
),
gguf_strides
(
1
,
2
,
2
*
4
),
random_tensor
((
2
,
4
,
2048
),
np
.
float16
),
random_tensor
((
2
,
4
,
2048
),
np
.
float16
),
(
4
*
2048
,
2048
,
1
),
gguf_strides
(
4
*
2048
,
2048
,
1
),
),
),
MulTestCase
(
MulTestCase
(
random_tensor
((
2
,
4
,
2048
),
np
.
float32
),
random_tensor
((
2
,
4
,
2048
),
np
.
float32
),
(
1
,
2
,
2
*
4
),
gguf_strides
(
1
,
2
,
2
*
4
),
random_tensor
((
2
,
4
,
2048
),
np
.
float32
),
random_tensor
((
2
,
4
,
2048
),
np
.
float32
),
None
,
None
,
random_tensor
((
2
,
4
,
2048
),
np
.
float32
),
random_tensor
((
2
,
4
,
2048
),
np
.
float32
),
(
1
,
2
,
2
*
4
),
gguf_strides
(
1
,
2
,
2
*
4
),
),
),
MulTestCase
(
MulTestCase
(
random_tensor
((
2048
,
2560
),
np
.
float32
),
random_tensor
((
2048
,
2560
),
np
.
float32
),
gguf_strides
(
2560
,
1
),
gguf_strides
(
2560
,
1
),
random_tensor
((
2048
,
2560
),
np
.
float32
),
random_tensor
((
2048
,
2560
),
np
.
float32
),
(
1
,
2048
),
gguf_strides
(
1
,
2048
),
random_tensor
((
2048
,
2560
),
np
.
float32
),
random_tensor
((
2048
,
2560
),
np
.
float32
),
gguf_strides
(
2560
,
1
),
gguf_strides
(
2560
,
1
),
),
),
MulTestCase
(
MulTestCase
(
random_tensor
((
4
,
48
,
64
),
np
.
float16
),
random_tensor
((
4
,
48
,
64
),
np
.
float16
),
(
64
*
48
,
64
,
1
),
gguf_strides
(
64
*
48
,
64
,
1
),
random_tensor
((
4
,
48
,
64
),
np
.
float16
),
random_tensor
((
4
,
48
,
64
),
np
.
float16
),
(
1
,
4
,
4
*
48
),
gguf_strides
(
1
,
4
,
4
*
48
),
random_tensor
((
4
,
48
,
64
),
np
.
float16
),
random_tensor
((
4
,
48
,
64
),
np
.
float16
),
None
None
),
),
...
@@ -153,11 +150,10 @@ if __name__ == '__main__':
...
@@ -153,11 +150,10 @@ if __name__ == '__main__':
random_tensor
((
4
,
48
,
64
),
np
.
float32
),
random_tensor
((
4
,
48
,
64
),
np
.
float32
),
None
,
None
,
random_tensor
((
4
,
48
,
64
),
np
.
float32
),
random_tensor
((
4
,
48
,
64
),
np
.
float32
),
(
1
,
4
,
4
*
48
),
gguf_strides
(
1
,
4
,
4
*
48
),
random_tensor
((
4
,
48
,
64
),
np
.
float32
),
random_tensor
((
4
,
48
,
64
),
np
.
float32
),
(
48
*
64
,
64
,
1
),
gguf_strides
(
48
*
64
,
64
,
1
),
),
)
]
]
test_writer
.
add_tests
(
test_cases
)
test_writer
.
add_tests
(
test_cases
)
test_writer
.
save
()
test_writer
.
save
()
test/infiniop/mul.py
View file @
03edef48
...
@@ -241,3 +241,4 @@ if __name__ == "__main__":
...
@@ -241,3 +241,4 @@ if __name__ == "__main__":
test_operator
(
lib
,
device
,
test
,
_TEST_CASES
,
_TENSOR_DTYPES
)
test_operator
(
lib
,
device
,
test
,
_TEST_CASES
,
_TENSOR_DTYPES
)
print
(
"
\033
[92mTest passed!
\033
[0m"
)
print
(
"
\033
[92mTest passed!
\033
[0m"
)
\ No newline at end of file
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