Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
12b2bf3
Add Add and AddScalar function declarations
aztice Jan 6, 2026
910366b
Update and rename include/axono/compute/cpu/operators/matmul.h to inc…
aztice Jan 6, 2026
413e0c5
Update and rename include/axono/compute/cpu/operators/randn.h to incl…
aztice Jan 6, 2026
64f1b70
Update and rename include/axono/compute/cpu/ops/relu.h to include/axo…
aztice Jan 6, 2026
a3e847f
Refactor namespace structure in add.h
aztice Jan 6, 2026
16b30fc
Update and rename include/axono/compute/cuda/operators/add.h to inclu…
aztice Jan 6, 2026
7755306
Update and rename include/axono/compute/cuda/operators/matmul.h to in…
aztice Jan 6, 2026
b8b37f5
Move randn.h to axono/ops/cuda directory
aztice Jan 6, 2026
7dfd254
Update and rename include/axono/compute/cuda/ops/relu.h to include/ax…
aztice Jan 6, 2026
c13bb27
Update module.h
aztice Jan 6, 2026
2c29dc5
Update ops.h
aztice Jan 6, 2026
e60b3af
Update tensor.h
aztice Jan 6, 2026
bc8d8f6
Update tensor.cpp
aztice Jan 6, 2026
7e0986c
Delete src/compute/cpu/operators/README.md
aztice Jan 6, 2026
7c84404
Update and rename src/compute/cpu/operators/add.cpp to src/ops/cpu/ad…
aztice Jan 6, 2026
b16c90e
Update matmul.cpp
aztice Jan 6, 2026
c18adeb
Rename src/compute/cpu/operators/matmul.cpp to src/ops/cpu/matmul.cpp
aztice Jan 6, 2026
74dfa75
Update and rename src/compute/cpu/operators/randn.cpp to src/ops/cpu/…
aztice Jan 6, 2026
ab08524
Refactor namespace structure in relu.cpp
aztice Jan 6, 2026
08b52fe
Delete src/compute/cpu/ops/README.md
aztice Jan 6, 2026
fd1dca5
Rename src/compute/cpu/ops/relu.cpp to src/ops/cpu/relu.cpp
aztice Jan 6, 2026
fea8e95
Delete src/compute/cuda/operators/README.md
aztice Jan 6, 2026
43f2b50
Update and rename src/compute/cuda/operators/add.cu to src/ops/cuda/a…
aztice Jan 6, 2026
8bcda7a
Update matmul.cu
aztice Jan 6, 2026
5c4bce8
Rename src/compute/cuda/operators/matmul.cu to src/ops/cuda/matmul.cu
aztice Jan 6, 2026
443512c
Update and rename src/compute/cuda/operators/randn.cu to src/ops/cuda…
aztice Jan 6, 2026
abc1535
Update and rename src/compute/cuda/ops/relu.cu to src/ops/cuda/relu.cu
aztice Jan 6, 2026
97b48b0
Delete src/compute/cuda/ops/README.md
aztice Jan 6, 2026
7606e7a
Update and rename add.h to add.h
aztice Jan 6, 2026
55ce776
Update and rename matmul.h to matmul.h
aztice Jan 6, 2026
832b1b6
Update relu.h
aztice Jan 6, 2026
c944ac3
Rename relu.h to relu.h
aztice Jan 6, 2026
6005a89
Rename include/axono/pybind/ops/cpu/add.h to include/axono/pybind/ops…
aztice Jan 6, 2026
4e9766b
Rename include/axono/pybind/ops/cpu/matmul.h to include/axono/pybind/…
aztice Jan 6, 2026
91f6a93
Rename include/axono/pybind/ops/cpu/relu.h to include/axono/pybind/op…
aztice Jan 6, 2026
4771ed4
Update pybind11_module.cpp
aztice Jan 6, 2026
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
10 changes: 8 additions & 2 deletions include/axono/core/module.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#pragma once

#include "tensor.h"

namespace axono::core {
namespace axono {
namespace core {

class Module {
private:
std::unordered_map<std::string, Tensor> weights_; // 存储权重张量
Expand All @@ -13,4 +17,6 @@ class Module {
}
auto& weights() { return weights_; }
};
}

} // namespace core
} // namespace axono
1 change: 1 addition & 0 deletions include/axono/core/ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,6 @@ class OpRegistry {
}; \
static RegisterOp_##name register_op_##name; \
pybind11::object op_impl_##name(const pybind11::args& args)

} // namespace core
} // namespace axono
2 changes: 2 additions & 0 deletions include/axono/core/tensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// 遵循 lib, type
namespace axono {
namespace core {

class Tensor {
public:
// 构造函数
Expand Down Expand Up @@ -103,5 +104,6 @@ class Tensor {
// 初始化数据存储
void InitializeStorage();
};

} // namespace core
} // namespace axono
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#pragma once

#include "axono/core/macros.h"
#include "axono/core/tensor.h"
#include "axono/core/types.h"

namespace axono {
namespace compute {
namespace ops {
namespace cpu {
namespace operators {

AXONO_EXPORT core::Status Add(const core::Context &ctx, const core::Tensor &a,
const core::Tensor &b, core::Tensor &result);
Expand All @@ -14,7 +15,6 @@ AXONO_EXPORT core::Status AddScalar(const core::Context &ctx,
const core::Tensor &a, void *scalar,
size_t scalar_size, core::Tensor &result);

} // namespace operators
} // namespace cpu
} // namespace compute
} // namespace ops
} // namespace axono
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@
#include "axono/core/tensor.h"

namespace axono {
namespace compute {
namespace ops {
namespace cpu {
namespace operators {

core::Status MatMul(const core::Context &ctx, const core::Tensor &a,
const core::Tensor &b, core::Tensor &result);

} // namespace operators
} // namespace cpu
} // namespace compute
} // namespace ops
} // namespace axono
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
#pragma once

#include "axono/core/tensor.h"
#include "axono/core/types.h"

namespace axono::compute::cuda::operators {
namespace axono {
namespace ops {
namespace cpu {

core::Status Randn(const core::Context& ctx, core::Tensor& out,
float mean = 0.0f, float stddev = 1.0f);

} // namespace axono::compute::cuda::operators
} // namespace cpu
} // namespace ops
} // namespace axono
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
#pragma once

#include "axono/core/macros.h"
#include "axono/core/tensor.h"
#include "axono/core/types.h"

namespace axono {
namespace compute {
namespace cpu {
namespace ops {
namespace cpu {

core::Status DispatchRelu(const core::Tensor &input, core::Tensor &output);
core::Status DispatchReluInplace(core::Tensor &tensor);
core::Status Relu(const core::Context &ctx, const core::Tensor &input,
core::Tensor &output);
core::Status ReluInplace(const core::Context &ctx, core::Tensor &tensor);

} // namespace ops
} // namespace cpu
} // namespace compute
} // namespace ops
} // namespace axono
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#pragma once

#include "axono/core/macros.h"
#include "axono/core/tensor.h"
#include "axono/core/types.h"

namespace axono {
namespace compute {
namespace ops {
namespace cuda {
namespace operators {

AXONO_EXPORT core::Status Add(const core::Context &ctx, const core::Tensor &a,
const core::Tensor &b, core::Tensor &result);
Expand All @@ -14,7 +15,6 @@ AXONO_EXPORT core::Status AddScalar(const core::Context &ctx,
const core::Tensor &a, void *scalar,
size_t scalar_size, core::Tensor &result);

} // namespace operators
} // namespace cuda
} // namespace compute
} // namespace ops
} // namespace axono
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
#pragma once

#include <cstddef>

#include "axono/core/macros.h"
#include "axono/core/tensor.h"
#include "axono/core/types.h"

namespace axono {
namespace compute {
namespace ops {
namespace cuda {
namespace operators {

core::Status MatMul(const core::Context &ctx, const core::Tensor &a,
const core::Tensor &b, core::Tensor &result);

}
} // namespace cuda
} // namespace compute
} // namespace ops
} // namespace axono
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
#pragma once

#include "axono/core/tensor.h"
#include "axono/core/types.h"

namespace axono::compute::cpu::operators {
namespace axono {
namespace ops {
namespace cuda {

core::Status Randn(const core::Context& ctx, core::Tensor& out,
float mean = 0.0f, float stddev = 1.0f);

} // namespace axono::compute::cpu::operators
} // namespace cuda
} // namespace ops
} // namespace axono
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
#pragma once

#include "axono/core/macros.h"
#include "axono/core/tensor.h"
#include "axono/core/types.h"

namespace axono {
namespace compute {
namespace cuda {
namespace ops {
namespace cuda {

core::Status DispatchRelu(const core::Tensor &input, core::Tensor &output);
core::Status DispatchReluInplace(core::Tensor &tensor);
core::Status Relu(const core::Context &ctx, const core::Tensor &input,
core::Tensor &output);
core::Status ReluInplace(const core::Context &ctx, core::Tensor &tensor);

} // namespace ops
} // namespace cuda
} // namespace compute
} // namespace ops
} // namespace axono
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
#include <pybind11/pybind11.h>

namespace py = pybind11;

#include "axono/core/ops.h"

#ifdef COMPILED_WITH_CUDA
#include "axono/compute/cuda/operators/add.h"
#include "axono/ops/cuda/add.h"
#endif
#include "axono/compute/cpu/operators/add.h"
#include "axono/ops/cpu/add.h"

namespace py = pybind11;

namespace axono {
namespace compute {
namespace operators {
namespace ops {

py::object op_impl_add(const py::args& args);
py::object op_impl_add_scalar(const py::args& args);
Expand All @@ -27,10 +26,10 @@ REGISTER_OP(add) {
core::Status status;
if (a.is_cuda()) {
#ifdef COMPILED_WITH_CUDA
status = cuda::operators::Add(ctx, a, b, result);
status = cuda::Add(ctx, a, b, result);
#endif
} else {
status = cpu::operators::Add(ctx, a, b, result);
status = cpu::Add(ctx, a, b, result);
}
if (status != core::Status::OK)
throw std::runtime_error("执行 add 时出现问题,错误代码:" + std::to_string(static_cast<int>(status)));
Expand All @@ -51,10 +50,10 @@ REGISTER_OP(add_scalar) {
float value = scalar.cast<float>();
if (a.is_cuda()){
#ifdef COMPILED_WITH_CUDA
status = cuda::operators::AddScalar(ctx, a, &value, sizeof(float), result);
status = cuda::AddScalar(ctx, a, &value, sizeof(float), result);
#endif
} else {
status = cpu::operators::AddScalar(ctx, a, &value, sizeof(float), result);
status = cpu::AddScalar(ctx, a, &value, sizeof(float), result);
}
}
if (status != core::Status::OK) {
Expand All @@ -63,10 +62,10 @@ REGISTER_OP(add_scalar) {
int32_t value = scalar.cast<int32_t>();
if (a.is_cuda()) {
#ifdef COMPILED_WITH_CUDA
status = cuda::operators::AddScalar(ctx, a, &value, sizeof(int32_t), result);
status = cuda::AddScalar(ctx, a, &value, sizeof(int32_t), result);
#endif
} else {
status = cpu::operators::AddScalar(ctx, a, &value, sizeof(int32_t), result);
status = cpu::AddScalar(ctx, a, &value, sizeof(int32_t), result);
}

if (status != core::Status::OK)
Expand All @@ -78,6 +77,5 @@ REGISTER_OP(add_scalar) {
return pybind11::cast(result);
}

}
}
}
} // namespace ops
} // namespace axono
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
#include <pybind11/pybind11.h>

namespace py = pybind11;

#ifdef COMPILED_WITH_CUDA
#include "axono/compute/cuda/operators/matmul.h"
#include "axono/ops/cuda/matmul.h"
#endif
#include "axono/compute/cpu/operators/matmul.h"
#include "axono/ops/cpu/matmul.h"

namespace py = pybind11;

namespace axono {
namespace compute {
namespace operators {
namespace ops {

py::object op_impl_matmul(const py::args& args);

Expand All @@ -19,26 +18,23 @@ REGISTER_OP(matmul) {
}
auto& a = pybind11::cast<core::Tensor&>(args[0]);
auto& b = pybind11::cast<core::Tensor&>(args[1]);
size_t m = a.shape()[0];
size_t n = b.shape()[1];
core::Context ctx;
core::Tensor result;
core::Status status;

core::Tensor result = core::Tensor(a.dtype(), std::vector<size_t>{m, n}, a.device());;
if (a.is_cuda()) {
#ifdef COMPILED_WITH_CUDA
size_t m = a.shape()[0];
size_t n = b.shape()[1];
auto result = core::Tensor(a.dtype(), std::vector<size_t>{m, n}, a.device());
status = cuda::operators::MatMul(ctx, a, b, result);
status = cuda::MatMul(ctx, a, b, result);
#endif
} else {
status = compute::cpu::operators::MatMul(ctx, a, b, result);
status = cpu::MatMul(ctx, a, b, result);
}
if (status != core::Status::OK)
throw std::runtime_error("执行 Matmul 时出现问题,错误代码:" + std::to_string(static_cast<int>(status)));

return pybind11::cast(result);
}

}
}
}
} // namespace ops
} // namespace axono
Loading