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
84d4ac48
Commit
84d4ac48
authored
Nov 19, 2025
by
zhuyue
Committed by
zhuyue
Nov 19, 2025
Browse files
Issue/626 - Add I32 and I64 dtype support to add operation (CPU) and tests.
parent
f69f6909
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
26 additions
and
6 deletions
+26
-6
src/infiniop/ops/add/cpu/add_cpu.cc
src/infiniop/ops/add/cpu/add_cpu.cc
+5
-1
src/infiniop/ops/add/nvidia/add_nvidia.cu
src/infiniop/ops/add/nvidia/add_nvidia.cu
+5
-1
test/infiniop/add.py
test/infiniop/add.py
+3
-1
test/infiniop/libinfiniop/utils.py
test/infiniop/libinfiniop/utils.py
+13
-3
No files found.
src/infiniop/ops/add/cpu/add_cpu.cc
View file @
84d4ac48
...
@@ -19,7 +19,7 @@ infiniStatus_t Descriptor::create(
...
@@ -19,7 +19,7 @@ infiniStatus_t Descriptor::create(
const
auto
&
a_shape
=
a_desc
->
shape
();
const
auto
&
a_shape
=
a_desc
->
shape
();
const
auto
&
b_shape
=
b_desc
->
shape
();
const
auto
&
b_shape
=
b_desc
->
shape
();
CHECK_DTYPE
(
dtype
,
INFINI_DTYPE_F16
,
INFINI_DTYPE_F32
,
INFINI_DTYPE_F64
,
INFINI_DTYPE_BF16
);
CHECK_DTYPE
(
dtype
,
INFINI_DTYPE_F16
,
INFINI_DTYPE_F32
,
INFINI_DTYPE_F64
,
INFINI_DTYPE_BF16
,
INFINI_DTYPE_I32
,
INFINI_DTYPE_I64
);
CHECK_SAME_SHAPE
(
c_shape
,
a_shape
,
b_shape
);
CHECK_SAME_SHAPE
(
c_shape
,
a_shape
,
b_shape
);
...
@@ -45,6 +45,10 @@ infiniStatus_t Descriptor::calculate(
...
@@ -45,6 +45,10 @@ infiniStatus_t Descriptor::calculate(
return
_device_info
->
calculate
<
AddOp
,
double
>
(
_info
,
output
,
inputs
,
stream
);
return
_device_info
->
calculate
<
AddOp
,
double
>
(
_info
,
output
,
inputs
,
stream
);
case
INFINI_DTYPE_BF16
:
case
INFINI_DTYPE_BF16
:
return
_device_info
->
calculate
<
AddOp
,
bf16_t
>
(
_info
,
output
,
inputs
,
stream
);
return
_device_info
->
calculate
<
AddOp
,
bf16_t
>
(
_info
,
output
,
inputs
,
stream
);
case
INFINI_DTYPE_I32
:
return
_device_info
->
calculate
<
AddOp
,
int32_t
>
(
_info
,
output
,
inputs
,
stream
);
case
INFINI_DTYPE_I64
:
return
_device_info
->
calculate
<
AddOp
,
int64_t
>
(
_info
,
output
,
inputs
,
stream
);
default:
default:
return
INFINI_STATUS_BAD_TENSOR_DTYPE
;
return
INFINI_STATUS_BAD_TENSOR_DTYPE
;
}
}
...
...
src/infiniop/ops/add/nvidia/add_nvidia.cu
View file @
84d4ac48
...
@@ -22,7 +22,7 @@ infiniStatus_t Descriptor::create(
...
@@ -22,7 +22,7 @@ infiniStatus_t Descriptor::create(
const
auto
&
a_shape
=
a_desc
->
shape
();
const
auto
&
a_shape
=
a_desc
->
shape
();
const
auto
&
b_shape
=
b_desc
->
shape
();
const
auto
&
b_shape
=
b_desc
->
shape
();
CHECK_DTYPE
(
dtype
,
INFINI_DTYPE_F16
,
INFINI_DTYPE_F32
,
INFINI_DTYPE_
F
64
,
INFINI_DTYPE_
BF16
);
CHECK_DTYPE
(
dtype
,
INFINI_DTYPE_F16
,
INFINI_DTYPE_F32
,
INFINI_DTYPE_
BF16
,
INFINI_DTYPE_I32
,
INFINI_DTYPE_I
64
,
INFINI_DTYPE_
F64
);
CHECK_SAME_SHAPE
(
c_shape
,
a_shape
,
b_shape
);
CHECK_SAME_SHAPE
(
c_shape
,
a_shape
,
b_shape
);
...
@@ -50,6 +50,10 @@ infiniStatus_t Descriptor::calculate(
...
@@ -50,6 +50,10 @@ infiniStatus_t Descriptor::calculate(
return
_device_info
->
calculate
<
256
,
cuda
::
AddOp
,
cuda_bfloat16
>
(
_info
,
workspace
,
output
,
inputs
,
stream
);
return
_device_info
->
calculate
<
256
,
cuda
::
AddOp
,
cuda_bfloat16
>
(
_info
,
workspace
,
output
,
inputs
,
stream
);
case
INFINI_DTYPE_F32
:
case
INFINI_DTYPE_F32
:
return
_device_info
->
calculate
<
256
,
cuda
::
AddOp
,
float
>
(
_info
,
workspace
,
output
,
inputs
,
stream
);
return
_device_info
->
calculate
<
256
,
cuda
::
AddOp
,
float
>
(
_info
,
workspace
,
output
,
inputs
,
stream
);
case
INFINI_DTYPE_I32
:
return
_device_info
->
calculate
<
256
,
cuda
::
AddOp
,
int32_t
>
(
_info
,
workspace
,
output
,
inputs
,
stream
);
case
INFINI_DTYPE_I64
:
return
_device_info
->
calculate
<
256
,
cuda
::
AddOp
,
int64_t
>
(
_info
,
workspace
,
output
,
inputs
,
stream
);
case
INFINI_DTYPE_F64
:
case
INFINI_DTYPE_F64
:
return
_device_info
->
calculate
<
256
,
cuda
::
AddOp
,
double
>
(
_info
,
workspace
,
output
,
inputs
,
stream
);
return
_device_info
->
calculate
<
256
,
cuda
::
AddOp
,
double
>
(
_info
,
workspace
,
output
,
inputs
,
stream
);
default:
default:
...
...
test/infiniop/add.py
View file @
84d4ac48
...
@@ -61,13 +61,15 @@ _TEST_CASES = [
...
@@ -61,13 +61,15 @@ _TEST_CASES = [
]
]
# Data types used for testing
# Data types used for testing
_TENSOR_DTYPES
=
[
InfiniDtype
.
F16
,
InfiniDtype
.
F32
,
InfiniDtype
.
BF16
]
_TENSOR_DTYPES
=
[
InfiniDtype
.
F16
,
InfiniDtype
.
F32
,
InfiniDtype
.
BF16
,
InfiniDtype
.
I32
,
InfiniDtype
.
I64
]
# Tolerance map for different data types
# Tolerance map for different data types
_TOLERANCE_MAP
=
{
_TOLERANCE_MAP
=
{
InfiniDtype
.
F16
:
{
"atol"
:
1e-3
,
"rtol"
:
1e-3
},
InfiniDtype
.
F16
:
{
"atol"
:
1e-3
,
"rtol"
:
1e-3
},
InfiniDtype
.
F32
:
{
"atol"
:
1e-7
,
"rtol"
:
1e-7
},
InfiniDtype
.
F32
:
{
"atol"
:
1e-7
,
"rtol"
:
1e-7
},
InfiniDtype
.
BF16
:
{
"atol"
:
1e-3
,
"rtol"
:
1e-3
},
InfiniDtype
.
BF16
:
{
"atol"
:
1e-3
,
"rtol"
:
1e-3
},
InfiniDtype
.
I32
:
{
"atol"
:
0
,
"rtol"
:
0
},
InfiniDtype
.
I64
:
{
"atol"
:
0
,
"rtol"
:
0
},
}
}
DEBUG
=
False
DEBUG
=
False
...
...
test/infiniop/libinfiniop/utils.py
View file @
84d4ac48
...
@@ -70,9 +70,19 @@ class TestTensor(CTensor):
...
@@ -70,9 +70,19 @@ class TestTensor(CTensor):
else
:
else
:
torch_shape
.
append
(
shape
[
i
])
torch_shape
.
append
(
shape
[
i
])
if
mode
==
"random"
:
if
mode
==
"random"
:
self
.
_torch_tensor
=
torch
.
rand
(
# For integer types, use randint instead of rand
torch_shape
,
dtype
=
to_torch_dtype
(
dt
),
device
=
torch_device_map
[
device
]
if
dt
in
[
InfiniDtype
.
I8
,
InfiniDtype
.
I16
,
InfiniDtype
.
I32
,
InfiniDtype
.
I64
,
)
InfiniDtype
.
U8
,
InfiniDtype
.
U16
,
InfiniDtype
.
U32
,
InfiniDtype
.
U64
,
InfiniDtype
.
BYTE
,
InfiniDtype
.
BOOL
]:
randint_low
=
-
2000000000
if
randint_low
is
None
else
randint_low
randint_high
=
2000000000
if
randint_high
is
None
else
randint_high
self
.
_torch_tensor
=
torch
.
randint
(
randint_low
,
randint_high
,
torch_shape
,
dtype
=
to_torch_dtype
(
dt
),
device
=
torch_device_map
[
device
]
)
else
:
self
.
_torch_tensor
=
torch
.
rand
(
torch_shape
,
dtype
=
to_torch_dtype
(
dt
),
device
=
torch_device_map
[
device
]
)
elif
mode
==
"zeros"
:
elif
mode
==
"zeros"
:
self
.
_torch_tensor
=
torch
.
zeros
(
self
.
_torch_tensor
=
torch
.
zeros
(
torch_shape
,
dtype
=
to_torch_dtype
(
dt
),
device
=
torch_device_map
[
device
]
torch_shape
,
dtype
=
to_torch_dtype
(
dt
),
device
=
torch_device_map
[
device
]
...
...
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