Commit d4c0cdf9 authored by Graylatzhou's avatar Graylatzhou
Browse files

issue/183 根据反馈修改

parent 975559ee
...@@ -17,10 +17,10 @@ __C __export infiniStatus_t infiniopMul(infiniopMulDescriptor_t desc, ...@@ -17,10 +17,10 @@ __C __export infiniStatus_t infiniopMul(infiniopMulDescriptor_t desc,
void *workspace, void *workspace,
size_t workspace_size, size_t workspace_size,
void *c, void *c,
void const *a, const void *a,
void const *b, const void *b,
void *stream); void *stream);
__C __export infiniStatus_t infiniopDestroyMulDescriptor(infiniopMulDescriptor_t desc); __C __export infiniStatus_t infiniopDestroyMulDescriptor(infiniopMulDescriptor_t desc);
#endif #endif
\ No newline at end of file
...@@ -80,13 +80,12 @@ std::shared_ptr<infiniop_test::Result> Test::run( ...@@ -80,13 +80,12 @@ std::shared_ptr<infiniop_test::Result> Test::run(
b->data(), b->data(),
nullptr); nullptr);
}, },
(warm_ups + 1) / 2, (iterations + 1) / 2); warm_ups, iterations);
return TEST_PASSED(elapsed_time); return TEST_PASSED(elapsed_time);
} }
std::vector<std::string> Test::attribute_names() { std::vector<std::string> Test::attribute_names() {
// MUL 操作不需要特殊属性(与 GEMM 不同,GEMM 需要 alpha 和 beta)
return {}; return {};
} }
...@@ -109,4 +108,4 @@ Test::~Test() { ...@@ -109,4 +108,4 @@ Test::~Test() {
delete _attributes; delete _attributes;
} }
} // namespace infiniop_test::mul } // namespace infiniop_test::mul
\ No newline at end of file
...@@ -16,4 +16,4 @@ public: ...@@ -16,4 +16,4 @@ public:
} MulOp; } MulOp;
} // namespace op::mul::cpu } // namespace op::mul::cpu
#endif // __MUL_CPU_H__ #endif // __MUL_CPU_H__
\ No newline at end of file
...@@ -54,4 +54,4 @@ infiniStatus_t Descriptor::calculate( ...@@ -54,4 +54,4 @@ infiniStatus_t Descriptor::calculate(
return INFINI_STATUS_SUCCESS; return INFINI_STATUS_SUCCESS;
} }
} // namespace op::add::cuda } // namespace op::mul::cuda
\ No newline at end of file
...@@ -5,4 +5,4 @@ ...@@ -5,4 +5,4 @@
ELEMENTWISE_DESCRIPTOR(mul, cuda) ELEMENTWISE_DESCRIPTOR(mul, cuda)
#endif // __MUL_CUDA_API_H__ #endif // __MUL_CUDA_API_H__
\ No newline at end of file
...@@ -21,6 +21,6 @@ typedef struct MulOp { ...@@ -21,6 +21,6 @@ typedef struct MulOp {
} }
} MulOp; } MulOp;
} // namespace op::add::cuda } // namespace op::mul::cuda
#endif // __MUL_CUDA_H__ #endif // __MUL_CUDA_H__
\ No newline at end of file
...@@ -117,4 +117,4 @@ infiniopDestroyMulDescriptor(infiniopMulDescriptor_t desc) { ...@@ -117,4 +117,4 @@ infiniopDestroyMulDescriptor(infiniopMulDescriptor_t desc) {
} }
#undef DELETE #undef DELETE
} }
\ No newline at end of file
from ast import List
import numpy as np import numpy as np
import gguf import gguf
from typing import List from typing import List
...@@ -54,101 +53,109 @@ class MulTestCase(InfiniopTestCase): ...@@ -54,101 +53,109 @@ class MulTestCase(InfiniopTestCase):
test_writer.add_tensor( test_writer.add_tensor(
test_writer.gguf_key("c"), self.c, raw_dtype=np_dtype_to_ggml(self.c.dtype) test_writer.gguf_key("c"), self.c, raw_dtype=np_dtype_to_ggml(self.c.dtype)
) )
a_fp64 = self.a.astype(np.float64)
b_fp64 = self.b.astype(np.float64)
ans_fp64 = np.multiply(a_fp64, b_fp64)
ans = mul(self.a, self.b, self.c) ans = mul(self.a, self.b, self.c)
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)
) )
test_writer.add_tensor(
test_writer.gguf_key("ans_fp64"),
ans_fp64,
raw_dtype=np_dtype_to_ggml(ans_fp64.dtype),
)
if __name__ == '__main__': if __name__ == '__main__':
test_writer = InfiniopTestWriter("mul.gguf") test_writer = InfiniopTestWriter("mul.gguf")
test_cases = [ test_cases = [
MulTestCase( MulTestCase(
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),
gguf_strides(3, 1), (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),
gguf_strides(3, 1), (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),
gguf_strides(3, 1), (1, 2),
), ),
MulTestCase( MulTestCase(
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),
gguf_strides(3, 1), gguf_strides(3, 1),
random_tensor((2, 3), np.float64), random_tensor((2, 3), np.float64),
gguf_strides(3, 1), (1, 2),
), ),
MulTestCase( MulTestCase(
random_tensor((4, 6), np.float16), random_tensor((4, 6), np.float16),
gguf_strides(1, 4), gguf_strides(1, 4),
random_tensor((4, 6), np.float16), random_tensor((4, 6), np.float16),
gguf_strides(1, 5), gguf_strides(1, 5),
random_tensor((4, 6), np.float16), random_tensor((4, 6), np.float16),
gguf_strides(1, 4), gguf_strides(6, 1),
), ),
MulTestCase( MulTestCase(
random_tensor((1, 2048), np.float16), random_tensor((1, 2048), np.float16),
gguf_strides(1, 2048), (1, 1),
random_tensor((1, 2048), np.float16), random_tensor((1, 2048), np.float16),
gguf_strides(1, 2048), gguf_strides(2048, 1),
random_tensor((1, 2048), np.float16), random_tensor((1, 2048), np.float16),
gguf_strides(1, 2048), (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),
None, (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),
None, (4 * 2048, 2048, 1),
random_tensor((2, 4, 2048), np.float16), random_tensor((2, 4, 2048), np.float16),
None, (1, 2, 2 * 4),
random_tensor((2, 4, 2048), np.float16), random_tensor((2, 4, 2048), np.float16),
None, (4 * 2048, 2048, 1),
), ),
MulTestCase( MulTestCase(
random_tensor((2, 4, 2048), np.float32), random_tensor((2, 4, 2048), np.float32),
None, (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),
None, (1, 2, 2 * 4),
), ),
MulTestCase( MulTestCase(
random_tensor((2048, 2560), np.float32), random_tensor((2048, 2560), np.float32),
gguf_strides(1, 2560), gguf_strides(2560, 1),
random_tensor((2048, 2560), np.float32), random_tensor((2048, 2560), np.float32),
gguf_strides(1, 2560), (1, 2048),
random_tensor((2048, 2560), np.float32), random_tensor((2048, 2560), np.float32),
gguf_strides(1, 2560), gguf_strides(2560, 1),
), ),
MulTestCase( MulTestCase(
random_tensor((4, 48, 64), np.float16), random_tensor((4, 48, 64), np.float16),
None, (64 * 48, 64, 1),
random_tensor((4, 48, 64), np.float16), random_tensor((4, 48, 64), np.float16),
None, (1, 4, 4 * 48),
random_tensor((4, 48, 64), np.float16), random_tensor((4, 48, 64), np.float16),
None None
), ),
MulTestCase( MulTestCase(
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),
None, (1, 4, 4 * 48),
random_tensor((4, 48, 64), np.float32), random_tensor((4, 48, 64), np.float32),
None (48 * 64, 64, 1),
), ),
] ]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment