Skip to content

Commit a30ca26

Browse files
Merge pull request #130 from YdrMaster/main
fix: fix for windows
2 parents 0ab53f1 + f33f6a2 commit a30ca26

File tree

10 files changed

+39
-82
lines changed

10 files changed

+39
-82
lines changed

include/data_type.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ typedef struct DataLayout {
99
mantissa : 8,
1010
exponent : 8;
1111

12+
#ifdef __cplusplus
1213
bool operator==(const DataLayout &other) const {
1314
union TypePun {
1415
DataLayout layout;
@@ -24,12 +25,13 @@ typedef struct DataLayout {
2425
bool operator!=(const DataLayout &other) const {
2526
return !(*this == other);
2627
}
28+
#endif
2729
} DataLayout;
2830

2931
typedef struct DataLayout DT;
3032

3133
// clang-format off
32-
constexpr static struct DataLayout
34+
const static struct DataLayout
3335
I8 = {1, 1, 1, 7, 0},
3436
I16 = {1, 1, 2, 15, 0},
3537
I32 = {1, 1, 4, 31, 0},

include/ops/gemm/gemm.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ __C __export infiniopStatus_t infiniopCreateGEMMDescriptor(infiniopHandle_t hand
1818
infiniopTensorDescriptor_t c_desc,
1919
float alpha,
2020
float beta,
21-
bool transA,
22-
bool transB);
21+
char transA,
22+
char transB);
2323

2424
__C __export infiniopStatus_t infiniopGetGEMMWorkspaceSize(infiniopGEMMDescriptor_t desc, uint64_t *size);
2525

include/ops/mlp/mlp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ __C __export infiniopStatus_t infiniopCreateMLPDescriptor(infiniopHandle_t handl
1919
infiniopTensorDescriptor_t w12_desc,
2020
infiniopTensorDescriptor_t w3_desc,
2121
float alpha,
22-
bool residual);
22+
char residual);
2323

2424
__C __export infiniopStatus_t infiniopGetMLPWorkspaceSize(infiniopMLPDescriptor_t desc, uint64_t *size);
2525

src/ops/conv/cpu/conv_cpu.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,8 @@ void _conv_cpu(ConvCpuDescriptor_t desc, void *workspace, uint64_t workspace_siz
173173
Ydata *y, Xdata const *x, Xdata const *w) {
174174
if (desc->padded_x_size > 0) {
175175
auto padded_x = reinterpret_cast<Xdata *>(workspace);
176-
uint64_t padded_shape[desc->ndim];
176+
std::vector<uint64_t> padded_shape_(desc->ndim);
177+
auto padded_shape = padded_shape_.data();
177178
std::fill(padded_x, padded_x + desc->padded_x_size, 0);
178179
getPaddedShape(desc->ndim, desc->x_shape, desc->pads, padded_shape);
179180
fillPaddedInput<Xdata>(desc, padded_shape, padded_x, x, desc->pads, 0, 0, 0);

src/ops/gemm/operator.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ __C __export infiniopStatus_t infiniopCreateGEMMDescriptor(infiniopHandle_t hand
2121
infiniopTensorDescriptor_t c_desc,
2222
float alpha,
2323
float beta,
24-
bool transA,
25-
bool transB) {
24+
char transA,
25+
char transB) {
2626
// transpose a and b if needed
2727
a_desc = transA ? permute(a_desc, {1, 0}) : a_desc;
2828
b_desc = transB ? permute(b_desc, {1, 0}) : b_desc;

src/ops/mlp/operator.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ __C __export infiniopStatus_t infiniopCreateMLPDescriptor(infiniopHandle_t handl
2626
infiniopTensorDescriptor_t w12_desc,
2727
infiniopTensorDescriptor_t w3_desc,
2828
float alpha,
29-
bool residual) {
29+
char residual) {
3030
if (y_desc->ndim != 2 || x_desc->ndim != 2 || w12_desc->ndim != 2 || w3_desc->ndim != 2) {
3131
return STATUS_BAD_TENSOR_SHAPE;
3232
}

src/ops/pooling/cpu/pooling_cpu.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,8 @@ void _pooling_cpu(PoolingCpuDescriptor_t desc, void *workspace, uint64_t workspa
191191
Ydata *y, Xdata const *x) {
192192
if (desc->padded_x_size > 0) {
193193
auto padded_x = reinterpret_cast<Xdata *>(workspace);
194-
uint64_t padded_shape[desc->ndim];
194+
std::vector<uint64_t> padded_shape_(desc->ndim);
195+
auto padded_shape = padded_shape_.data();
195196
std::fill(padded_x, padded_x + desc->padded_x_size, 0);
196197
getPaddedShape(desc->ndim, desc->x_shape, desc->pads, padded_shape);
197198
fillPaddedInput<Xdata>(desc, padded_shape, padded_x, x, desc->pads, 0, 0, 0);

src/ops/random_sample/cpu/random_sample.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ infiniopStatus_t cpuCreateRandomSampleDescriptor(infiniopHandle_t,
3131
return STATUS_SUCCESS;
3232
}
3333

34-
infiniopStatus_t cpuGetRandomSampleWorkspaceSize(RandomSampleCpuDescriptor_t desc, unsigned long int *size) {
34+
infiniopStatus_t cpuGetRandomSampleWorkspaceSize(RandomSampleCpuDescriptor_t desc, uint64_t *size) {
3535
*size = desc->voc * (sizeof(uint64_t) + sizeof(desc->dtype));
3636
return STATUS_SUCCESS;
3737
}

src/ops/utils.h

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,14 @@ inline bool getBroadcastShape(const uint64_t *shape1, uint64_t ndim1,
106106

107107
// check if the shape of tensor c is valid after broadcasting tensors a and b and also get the broadcasted shapes
108108
inline bool isValidBroadcastShape(infiniopTensorDescriptor_t a, infiniopTensorDescriptor_t b, infiniopTensorDescriptor_t c,
109-
uint64_t *broadcast_shape, uint64_t *padded_shape1, uint64_t *padded_shape2, uint64_t broadcast_ndim) {
109+
uint64_t broadcast_ndim) {
110+
std::vector<uint64_t>
111+
broadcast_shape_(broadcast_ndim),
112+
padded_shape1_(broadcast_ndim),
113+
padded_shape2_(broadcast_ndim);
114+
auto broadcast_shape = broadcast_shape_.data(),
115+
padded_shape1 = padded_shape1_.data(),
116+
padded_shape2 = padded_shape2_.data();
110117
if (broadcast_ndim != c->ndim || !getBroadcastShape(a->shape, a->ndim, b->shape, b->ndim, broadcast_shape, padded_shape1, padded_shape2, broadcast_ndim)) {
111118
return false;
112119
}
@@ -118,7 +125,8 @@ inline bool isValidBroadcastShape(infiniopTensorDescriptor_t dst, infiniopTensor
118125
if (dst->ndim < src->ndim) {
119126
return false;
120127
}
121-
uint64_t padded_shape[dst->ndim];
128+
std::vector<uint64_t> padded_shape_(dst->ndim);
129+
auto padded_shape = padded_shape_.data();
122130
std::fill(padded_shape, padded_shape + dst->ndim, 1);
123131
std::copy(src->shape, src->shape + src->ndim, padded_shape + dst->ndim - src->ndim);
124132
for (size_t i = 0; i < dst->ndim; ++i) {
@@ -131,11 +139,7 @@ inline bool isValidBroadcastShape(infiniopTensorDescriptor_t dst, infiniopTensor
131139

132140
// check if the shape of tensor c is valid after broadcasting tensors a and b
133141
inline bool isValidBroadcastShape(infiniopTensorDescriptor_t a, infiniopTensorDescriptor_t b, infiniopTensorDescriptor_t c) {
134-
uint64_t broadcast_ndim = std::max(a->ndim, b->ndim);
135-
uint64_t broadcast_shape[broadcast_ndim];
136-
uint64_t padded_shape1[broadcast_ndim];
137-
uint64_t padded_shape2[broadcast_ndim];
138-
return isValidBroadcastShape(a, b, c, broadcast_shape, padded_shape1, padded_shape2, broadcast_ndim);
142+
return isValidBroadcastShape(a, b, c, std::max(a->ndim, b->ndim));
139143
}
140144

141145
inline uint64_t get_byte_size(infiniopTensorDescriptor_t desc) {
@@ -220,7 +224,7 @@ inline infiniopTensorDescriptor_t dim_merge(infiniopTensorDescriptor_t desc, uin
220224
// split the dimension dim of a tensor descriptor into multiple dimensions
221225
inline infiniopTensorDescriptor_t dim_split(infiniopTensorDescriptor_t desc, uint64_t dim, const std::vector<uint64_t> &dims) {
222226
uint64_t ndim = desc->ndim;
223-
if (static_cast<int64_t>(desc->shape[dim]) != std::accumulate(dims.begin(), dims.end(), 1, std::multiplies<uint64_t>())) {
227+
if (desc->shape[dim] != std::accumulate(dims.begin(), dims.end(), 1, std::multiplies{})) {
224228
return nullptr;
225229
}
226230
uint64_t new_ndim = ndim + dims.size() - 1;

xmake.lua

Lines changed: 13 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
add_rules("mode.debug", "mode.release")
2+
-- Define color codes
3+
local GREEN = '\27[0;32m'
4+
local YELLOW = '\27[1;33m'
5+
local NC = '\27[0m' -- No Color
26

37
add_includedirs("include")
48

@@ -116,7 +120,7 @@ if has_config("cambricon-mlu") then
116120

117121
local includedirs = table.concat(target:get("includedirs"), " ")
118122
local args = {"-c", sourcefile, "-o", objectfile, "-I/usr/local/neuware/include", "--bang-mlu-arch=mtp_592", "-O3", "-fPIC", "-Wall", "-Werror", "-std=c++17", "-pthread"}
119-
123+
120124
for _, includedir in ipairs(target:get("includedirs")) do
121125
table.insert(args, "-I" .. includedir)
122126
end
@@ -127,7 +131,6 @@ if has_config("cambricon-mlu") then
127131

128132
rule_end()
129133

130-
131134
target("cambricon-mlu")
132135
set_kind("static")
133136
on_install(function (target) end)
@@ -152,7 +155,7 @@ if has_config("ascend-npu") then
152155
add_links("libascendcl.so")
153156
add_links("libnnopbase.so")
154157
add_links("libopapi.so")
155-
add_links("libruntime.so")
158+
add_links("libruntime.so")
156159
add_linkdirs(ASCEND_HOME .. "/../../driver/lib64/driver")
157160
add_links("libascend_hal.so")
158161
local builddir = string.format(
@@ -169,15 +172,15 @@ if has_config("ascend-npu") then
169172
os.exec("make")
170173
os.exec("cp $(projectdir)/src/devices/ascend/build/lib/libascend_kernels.a "..builddir.."/")
171174
os.cd(os.projectdir())
172-
175+
173176
end)
174177
after_clean(function ()
175178
local ascend_build_dir = path.join(os.projectdir(), "src/devices/ascend")
176179
os.cd(ascend_build_dir)
177180
os.exec("make clean")
178181
os.cd(os.projectdir())
179182
os.rm(builddir.. "/libascend_kernels.a")
180-
183+
181184
end)
182185
rule_end()
183186

@@ -190,7 +193,7 @@ if has_config("ascend-npu") then
190193
add_files("src/devices/ascend/*.cc", "src/ops/*/ascend/*.cc")
191194
add_cxflags("-lstdc++ -Wall -Werror -fPIC")
192195

193-
-- Add operator
196+
-- Add operator
194197
add_rules("ascend-kernels")
195198
add_links(builddir.."/libascend_kernels.a")
196199

@@ -216,64 +219,10 @@ target("infiniop")
216219
add_files("src/devices/handle.cc")
217220
add_files("src/ops/*/operator.cc")
218221
add_files("src/tensor/*.cc")
222+
after_build(function (target) print(YELLOW .. "You can install the libraries with \"xmake install\"" .. NC) end)
219223

220-
after_build(function (target)
221-
local builddir = string.format(
222-
"%s/build/%s/%s/%s",
223-
os.projectdir(),
224-
get_config("plat"),
225-
get_config("arch"),
226-
get_config("mode")
227-
)
228-
229-
-- Define color codes
230-
local GREEN = '\27[0;32m'
231-
local YELLOW = '\27[1;33m'
232-
local NC = '\27[0m' -- No Color
233-
234-
-- Get the current directory
235-
local current_dir = os.curdir()
236-
237-
-- Output messages with colors
238-
os.exec("echo -e '" .. GREEN .. "Compilation completed successfully." .. NC .. "'")
239-
os.exec("echo -e '" .. YELLOW .. "You can install the libraries with \"xmake install\"" .. NC .. "'")
240-
end)
241-
242-
on_install(function (target)
243-
print("Installing libraries...")
244-
245-
local GREEN = '\27[0;32m'
246-
local YELLOW = '\27[1;33m'
247-
local NC = '\27[0m' -- No Color
248-
249-
local infini_dir = os.getenv("INFINI_ROOT")
250-
if infini_dir == nil then
251-
print(YELLOW .. "INFINI_ROOT not set, installation path default to ~/.infini".. NC)
252-
print(YELLOW .. "It is recommended to set INFINI_ROOT as an environment variable." .. NC)
253-
infini_dir = os.getenv("HOME") .. "/.infini"
254-
end
255-
256-
if os.isdir(infini_dir) then
257-
print("INFINI_ROOT already exists, duplicated contents will be overwritten.")
258-
else
259-
os.mkdir(infini_dir)
260-
end
261-
262-
local builddir = string.format(
263-
"%s/build/%s/%s/%s",
264-
os.projectdir(),
265-
get_config("plat"),
266-
get_config("arch"),
267-
get_config("mode")
268-
)
269-
os.exec("mkdir -p " .. infini_dir .. "/lib")
270-
os.exec("cp " ..builddir.. "/libinfiniop.so " .. infini_dir .. "/lib/")
271-
os.exec("cp -r $(projectdir)/include " .. infini_dir .. "/include")
272-
273-
os.exec("echo -e '" .. GREEN .. "Installation completed successfully at " .. infini_dir .. NC .. "'")
274-
os.exec("echo -e '" .. YELLOW .. "To set the environment variables, you can run the following command:" .. NC .. "'")
275-
os.exec("echo -e '" .. YELLOW .. "export INFINI_ROOT=" .. infini_dir .. NC .. "'")
276-
os.exec("echo -e '" .. YELLOW .. "export LD_LIBRARY_PATH=:$INFINI_ROOT/lib:$LD_LIBRARY_PATH" .. NC .. "'")
277-
end)
224+
set_installdir(os.getenv("INFINI_ROOT") or (os.getenv(is_host("windows") and "HOMEPATH" or "HOME") .. "/.infini"))
225+
add_installfiles("include/(**/*.h)", {prefixdir = "include"})
226+
add_installfiles("include/*.h", {prefixdir = "include"})
278227

279228
target_end()

0 commit comments

Comments
 (0)