Skip to content

Commit bd932e6

Browse files
committed
formated
1 parent 3ad6339 commit bd932e6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+655
-458
lines changed

src/infiniop-test/include/ops.hpp

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -39,29 +39,28 @@ DECLARE_INFINIOP_TEST(cross_entropy_loss_backward)
3939
/*
4040
* Register all the tests here
4141
*/
42-
#define TEST_BUILDER_MAPPINGS \
43-
{ \
44-
REGISTER_INFINIOP_TEST(gemm) \
45-
REGISTER_INFINIOP_TEST(random_sample) \
46-
REGISTER_INFINIOP_TEST(add) \
47-
REGISTER_INFINIOP_TEST(mul) \
48-
REGISTER_INFINIOP_TEST(clip) \
49-
REGISTER_INFINIOP_TEST(swiglu) \
50-
REGISTER_INFINIOP_TEST(rope) \
51-
REGISTER_INFINIOP_TEST(rms_norm) \
52-
REGISTER_INFINIOP_TEST(causal_softmax) \
53-
REGISTER_INFINIOP_TEST(rearrange) \
54-
REGISTER_INFINIOP_TEST(sub) \
55-
REGISTER_INFINIOP_TEST(div) \
56-
REGISTER_INFINIOP_TEST(silu) \
57-
REGISTER_INFINIOP_TEST(logical_and) \
58-
REGISTER_INFINIOP_TEST(logical_or) \
59-
REGISTER_INFINIOP_TEST(equal) \
60-
REGISTER_INFINIOP_TEST(relu_backward) \
61-
REGISTER_INFINIOP_TEST(gelu) \
62-
REGISTER_INFINIOP_TEST(gelu_backward) \
63-
REGISTER_INFINIOP_TEST(cross_entropy_loss_backward) \
64-
}
42+
#define TEST_BUILDER_MAPPINGS \
43+
{ \
44+
REGISTER_INFINIOP_TEST(gemm) \
45+
REGISTER_INFINIOP_TEST(random_sample) \
46+
REGISTER_INFINIOP_TEST(add) \
47+
REGISTER_INFINIOP_TEST(mul) \
48+
REGISTER_INFINIOP_TEST(clip) \
49+
REGISTER_INFINIOP_TEST(swiglu) \
50+
REGISTER_INFINIOP_TEST(rope) \
51+
REGISTER_INFINIOP_TEST(rms_norm) \
52+
REGISTER_INFINIOP_TEST(causal_softmax) \
53+
REGISTER_INFINIOP_TEST(rearrange) \
54+
REGISTER_INFINIOP_TEST(sub) \
55+
REGISTER_INFINIOP_TEST(div) \
56+
REGISTER_INFINIOP_TEST(silu) \
57+
REGISTER_INFINIOP_TEST(logical_and) \
58+
REGISTER_INFINIOP_TEST(logical_or) \
59+
REGISTER_INFINIOP_TEST(equal) \
60+
REGISTER_INFINIOP_TEST(relu_backward) \
61+
REGISTER_INFINIOP_TEST(gelu) \
62+
REGISTER_INFINIOP_TEST(gelu_backward) \
63+
REGISTER_INFINIOP_TEST(cross_entropy_loss_backward)}
6564

6665
namespace infiniop_test {
6766

src/infiniop-test/include/test.hpp

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,16 @@ std::vector<std::shared_ptr<Result>> runAllTests(
4747
const GGUFFileReader &,
4848
infiniDevice_t device, int device_id,
4949
size_t warm_ups, size_t iterations,
50-
double rtol, double atol, bool equal_nan=false);
50+
double rtol, double atol, bool equal_nan = false);
5151

5252
// Run a single test read from a GGUF file
5353
std::shared_ptr<Result> runTest(
5454
const GGUFFileReader &,
5555
infiniDevice_t device, int device_id,
5656
size_t warm_ups, size_t iterations,
5757
double rtol, double atol,
58-
size_t test_id,
59-
bool equal_nan=false);
58+
size_t test_id,
59+
bool equal_nan = false);
6060

6161
// Check if two tensors are close within given tolerance
6262
void allClose(std::shared_ptr<Tensor> actual, std::shared_ptr<Tensor> expected, double rtol = 1e-3, double atol = 1e-3, bool equal_nan = false);
@@ -82,38 +82,38 @@ class Test {
8282
} // namespace infiniop_test::base
8383

8484
// Quick macro for declaring a new testcase
85-
#define DECLARE_INFINIOP_TEST(name) \
86-
namespace infiniop_test::name { \
87-
class Test : public infiniop_test::base::Test { \
88-
double _rtol, _atol; \
89-
bool _equal_nan; \
90-
\
91-
public: \
92-
static std::string op_name() { return #name; } \
93-
static std::shared_ptr<Test> build( \
94-
std::unordered_map<std::string, std::vector<uint8_t>> attributes, \
95-
std::unordered_map<std::string, std::shared_ptr<Tensor>> tensors, \
96-
double, double, bool); \
97-
\
98-
static std::vector<std::string> attribute_names(); \
99-
static std::vector<std::string> tensor_names(); \
100-
static std::vector<std::string> output_names(); \
101-
\
102-
std::shared_ptr<infiniop_test::Result> run( \
103-
infiniopHandle_t handle, infiniDevice_t device, int device_id, \
104-
size_t warm_ups, size_t iterations) override; \
105-
\
106-
std::string toString() const override; \
107-
\
108-
~Test(); \
109-
\
110-
private: \
111-
struct Attributes; \
112-
Attributes *_attributes; \
113-
Test() = delete; \
114-
Test(double rtol, double atol, bool equal_nan = false) \
115-
: _rtol(rtol), _atol(atol), _equal_nan(equal_nan) {} \
116-
}; \
85+
#define DECLARE_INFINIOP_TEST(name) \
86+
namespace infiniop_test::name { \
87+
class Test : public infiniop_test::base::Test { \
88+
double _rtol, _atol; \
89+
bool _equal_nan; \
90+
\
91+
public: \
92+
static std::string op_name() { return #name; } \
93+
static std::shared_ptr<Test> build( \
94+
std::unordered_map<std::string, std::vector<uint8_t>> attributes, \
95+
std::unordered_map<std::string, std::shared_ptr<Tensor>> tensors, \
96+
double, double, bool); \
97+
\
98+
static std::vector<std::string> attribute_names(); \
99+
static std::vector<std::string> tensor_names(); \
100+
static std::vector<std::string> output_names(); \
101+
\
102+
std::shared_ptr<infiniop_test::Result> run( \
103+
infiniopHandle_t handle, infiniDevice_t device, int device_id, \
104+
size_t warm_ups, size_t iterations) override; \
105+
\
106+
std::string toString() const override; \
107+
\
108+
~Test(); \
109+
\
110+
private: \
111+
struct Attributes; \
112+
Attributes *_attributes; \
113+
Test() = delete; \
114+
Test(double rtol, double atol, bool equal_nan = false) \
115+
: _rtol(rtol), _atol(atol), _equal_nan(equal_nan) {} \
116+
}; \
117117
}
118118

119119
namespace infiniop_test {

src/infiniop-test/src/main.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#include "gguf.hpp"
22
#include "test.hpp"
3+
#include <cstring>
34
#include <infinirt.h>
45
#include <iostream>
5-
#include <cstring>
66
struct ParsedArgs {
77
std::string file_path; // Mandatory argument: test.gguf file path
88
infiniDevice_t device_type = INFINI_DEVICE_CPU; // Default to CPU
@@ -96,8 +96,9 @@ ParsedArgs parseArgs(int argc, char *argv[]) {
9696
args.rtol = std::stod(argv[++i]);
9797
}
9898
else if (arg == "--equal-nan" && i + 1 < argc) {
99-
args.equal_nan = (strcmp(argv[++i], "True") == 0 || strcmp(argv[i], "true") == 0)
100-
? true : false;
99+
args.equal_nan = (strcmp(argv[++i], "True") == 0 || strcmp(argv[i], "true") == 0)
100+
? true
101+
: false;
101102
}
102103
else {
103104
printUsage();

src/infiniop-test/src/ops/cross_entropy_loss_backward.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
namespace infiniop_test::cross_entropy_loss_backward {
88

99
struct Test::Attributes {
10-
std::shared_ptr<Tensor> probs; // 概率 (softmax 输出)
11-
std::shared_ptr<Tensor> target; // one-hot 标签 (与 logits 同形状)
12-
std::shared_ptr<Tensor> grad_logits; // 输出: dL/dlogits
13-
std::shared_ptr<Tensor> ans; // 参考结果
10+
std::shared_ptr<Tensor> probs; // 概率 (softmax 输出)
11+
std::shared_ptr<Tensor> target; // one-hot 标签 (与 logits 同形状)
12+
std::shared_ptr<Tensor> grad_logits; // 输出: dL/dlogits
13+
std::shared_ptr<Tensor> ans; // 参考结果
1414
};
1515

1616
std::shared_ptr<Test> Test::build(
@@ -28,10 +28,10 @@ std::shared_ptr<Test> Test::build(
2828
throw std::runtime_error("Invalid Test");
2929
}
3030

31-
test->_attributes->probs = tensors["probs"];
32-
test->_attributes->target = tensors["target"];
33-
test->_attributes->grad_logits = tensors["grad_logits"];
34-
test->_attributes->ans = tensors["ans"];
31+
test->_attributes->probs = tensors["probs"];
32+
test->_attributes->target = tensors["target"];
33+
test->_attributes->grad_logits = tensors["grad_logits"];
34+
test->_attributes->ans = tensors["ans"];
3535

3636
return test;
3737
}
@@ -42,8 +42,8 @@ std::shared_ptr<infiniop_test::Result> Test::run(
4242

4343
infiniopCrossEntropyLossBackwardDescriptor_t op_desc;
4444

45-
auto probs = _attributes->probs->to(device, device_id);
46-
auto target = _attributes->target->to(device, device_id);
45+
auto probs = _attributes->probs->to(device, device_id);
46+
auto target = _attributes->target->to(device, device_id);
4747
auto grad_logits = _attributes->grad_logits->to(device, device_id);
4848

4949
CHECK_OR(infiniopCreateCrossEntropyLossBackwardDescriptor(
@@ -57,7 +57,7 @@ std::shared_ptr<infiniop_test::Result> Test::run(
5757
CHECK_OR(infiniopGetCrossEntropyLossBackwardWorkspaceSize(op_desc, &workspace_size),
5858
return TEST_FAILED(OP_CREATION_FAILED, "Failed to get workspace size."));
5959

60-
void* workspace = nullptr;
60+
void *workspace = nullptr;
6161
CHECK_OR(infinirtMalloc(&workspace, workspace_size),
6262
return TEST_FAILED(OP_CREATION_FAILED, "Failed to allocate workspace."));
6363

@@ -72,7 +72,7 @@ std::shared_ptr<infiniop_test::Result> Test::run(
7272
try {
7373
// 浮点比较;如混合精度,建议设置合理的 rtol/atol
7474
allClose(grad_logits, _attributes->ans, _rtol, _atol, _equal_nan);
75-
} catch (const std::exception& e) {
75+
} catch (const std::exception &e) {
7676
infiniopDestroyCrossEntropyLossBackwardDescriptor(op_desc);
7777
infinirtFree(workspace);
7878
return TEST_FAILED(RESULT_INCORRECT, e.what());
@@ -108,8 +108,8 @@ std::vector<std::string> Test::output_names() {
108108
std::string Test::toString() const {
109109
std::ostringstream oss;
110110
oss << op_name() << std::endl;
111-
oss << "- probs: " << _attributes->probs->info() << std::endl;
112-
oss << "- target: " << _attributes->target->info() << std::endl;
111+
oss << "- probs: " << _attributes->probs->info() << std::endl;
112+
oss << "- target: " << _attributes->target->info() << std::endl;
113113
oss << "- grad_logits: " << _attributes->grad_logits->info() << std::endl;
114114
oss << std::scientific << std::setprecision(2);
115115
oss << "- rtol=" << _rtol << ", atol=" << _atol

src/infiniop-test/src/ops/equal.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ std::shared_ptr<Test> Test::build(
2626
throw std::runtime_error("Invalid Test");
2727
}
2828

29-
test->_attributes->a = tensors["a"];
30-
test->_attributes->b = tensors["b"];
31-
test->_attributes->c = tensors["c"];
29+
test->_attributes->a = tensors["a"];
30+
test->_attributes->b = tensors["b"];
31+
test->_attributes->c = tensors["c"];
3232
test->_attributes->ans = tensors["ans"];
3333
return test;
3434
}
@@ -52,7 +52,7 @@ std::shared_ptr<infiniop_test::Result> Test::run(
5252
CHECK_OR(infiniopGetEqualWorkspaceSize(op_desc, &workspace_size),
5353
return TEST_FAILED(OP_CREATION_FAILED, "Failed to get workspace size."));
5454

55-
void* workspace;
55+
void *workspace;
5656
CHECK_OR(infinirtMalloc(&workspace, workspace_size),
5757
return TEST_FAILED(OP_CREATION_FAILED, "Failed to allocate workspace."));
5858

@@ -66,7 +66,7 @@ std::shared_ptr<infiniop_test::Result> Test::run(
6666
try {
6767
// 输出为 bool,使用布尔比较
6868
allEqual(c, _attributes->ans);
69-
} catch (const std::exception& e) {
69+
} catch (const std::exception &e) {
7070
infiniopDestroyEqualDescriptor(op_desc);
7171
infinirtFree(workspace);
7272
return TEST_FAILED(RESULT_INCORRECT, e.what());

src/infiniop-test/src/ops/gelu.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ std::shared_ptr<Test> Test::build(
2525
throw std::runtime_error("Invalid Test");
2626
}
2727

28-
test->_attributes->input = tensors["input"];
28+
test->_attributes->input = tensors["input"];
2929
test->_attributes->output = tensors["output"];
30-
test->_attributes->ans = tensors["ans"];
30+
test->_attributes->ans = tensors["ans"];
3131
return test;
3232
}
3333

@@ -37,7 +37,7 @@ std::shared_ptr<infiniop_test::Result> Test::run(
3737

3838
infiniopGeluDescriptor_t op_desc;
3939

40-
auto input = _attributes->input->to(device, device_id);
40+
auto input = _attributes->input->to(device, device_id);
4141
auto output = _attributes->output->to(device, device_id);
4242

4343
CHECK_OR(infiniopCreateGeluDescriptor(handle, &op_desc,
@@ -49,7 +49,7 @@ std::shared_ptr<infiniop_test::Result> Test::run(
4949
CHECK_OR(infiniopGetGeluWorkspaceSize(op_desc, &workspace_size),
5050
return TEST_FAILED(OP_CREATION_FAILED, "Failed to get workspace size."));
5151

52-
void* workspace;
52+
void *workspace;
5353
CHECK_OR(infinirtMalloc(&workspace, workspace_size),
5454
return TEST_FAILED(OP_CREATION_FAILED, "Failed to allocate workspace."));
5555

@@ -61,7 +61,7 @@ std::shared_ptr<infiniop_test::Result> Test::run(
6161

6262
try {
6363
allClose(output, _attributes->ans, _rtol, _atol, _equal_nan);
64-
} catch (const std::exception& e) {
64+
} catch (const std::exception &e) {
6565
infiniopDestroyGeluDescriptor(op_desc);
6666
infinirtFree(workspace);
6767
return TEST_FAILED(RESULT_INCORRECT, e.what());
@@ -91,7 +91,7 @@ std::vector<std::string> Test::output_names() { return {"output"}; }
9191
std::string Test::toString() const {
9292
std::ostringstream oss;
9393
oss << op_name() << std::endl;
94-
oss << "- input: " << _attributes->input->info() << std::endl;
94+
oss << "- input: " << _attributes->input->info() << std::endl;
9595
oss << "- output: " << _attributes->output->info() << std::endl;
9696
oss << std::scientific << std::setprecision(2);
9797
oss << "- rtol=" << _rtol << ", atol=" << _atol << ", equal_nan=" << _equal_nan << std::endl;

0 commit comments

Comments
 (0)