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
93e7d887
Unverified
Commit
93e7d887
authored
Oct 11, 2025
by
Jiacheng Huang
Committed by
GitHub
Oct 11, 2025
Browse files
issue/492: 修复 infinicore.Tensor.dtype 和 infinicore.Tensor.device 返回类型的问题
parent
9a05446f
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
41 additions
and
12 deletions
+41
-12
include/infinicore/device.hpp
include/infinicore/device.hpp
+1
-1
python/infinicore/__init__.py
python/infinicore/__init__.py
+2
-0
python/infinicore/device.py
python/infinicore/device.py
+18
-1
python/infinicore/tensor.py
python/infinicore/tensor.py
+13
-4
src/infinicore/device.cc
src/infinicore/device.cc
+2
-2
src/infinicore/pybind11/device.hpp
src/infinicore/pybind11/device.hpp
+1
-1
src/infinicore/pybind11/tensor.hpp
src/infinicore/pybind11/tensor.hpp
+1
-0
test/infinicore/framework/devices.py
test/infinicore/framework/devices.py
+3
-3
No files found.
include/infinicore/device.hpp
View file @
93e7d887
...
@@ -20,7 +20,7 @@ public:
...
@@ -20,7 +20,7 @@ public:
MOORE
=
INFINI_DEVICE_MOORE
,
MOORE
=
INFINI_DEVICE_MOORE
,
ILUVATAR
=
INFINI_DEVICE_ILUVATAR
,
ILUVATAR
=
INFINI_DEVICE_ILUVATAR
,
KUNLUN
=
INFINI_DEVICE_KUNLUN
,
KUNLUN
=
INFINI_DEVICE_KUNLUN
,
SU
GON
=
INFINI_DEVICE_
SU
GON
,
HY
GON
=
INFINI_DEVICE_
HY
GON
,
COUNT
=
INFINI_DEVICE_TYPE_COUNT
,
COUNT
=
INFINI_DEVICE_TYPE_COUNT
,
};
};
...
...
python/infinicore/__init__.py
View file @
93e7d887
...
@@ -9,6 +9,7 @@ from infinicore.dtype import (
...
@@ -9,6 +9,7 @@ from infinicore.dtype import (
complex64
,
complex64
,
complex128
,
complex128
,
double
,
double
,
dtype
,
float
,
float
,
float16
,
float16
,
float32
,
float32
,
...
@@ -37,6 +38,7 @@ from infinicore.tensor import (
...
@@ -37,6 +38,7 @@ from infinicore.tensor import (
__all__
=
[
__all__
=
[
# Classes.
# Classes.
"device"
,
"device"
,
"dtype"
,
# Data Types.
# Data Types.
"bfloat16"
,
"bfloat16"
,
"bool"
,
"bool"
,
...
...
python/infinicore/device.py
View file @
93e7d887
...
@@ -66,6 +66,23 @@ class device:
...
@@ -66,6 +66,23 @@ class device:
index
-=
1
index
-=
1
@
staticmethod
def
_from_infinicore_device
(
infinicore_device
):
type
=
_TORCH_DEVICE_MAP
[
infinicore_device
.
type
]
base_index
=
0
for
infinicore_type
,
torch_type
in
_TORCH_DEVICE_MAP
.
items
():
if
torch_type
!=
type
:
continue
if
infinicore_type
==
infinicore_device
.
type
:
break
base_index
+=
_infinicore
.
get_device_count
(
infinicore_device
)
return
device
(
type
,
base_index
+
infinicore_device
.
index
)
_TORCH_DEVICE_MAP
=
{
_TORCH_DEVICE_MAP
=
{
_infinicore
.
Device
.
Type
.
CPU
:
"cpu"
,
_infinicore
.
Device
.
Type
.
CPU
:
"cpu"
,
...
@@ -76,5 +93,5 @@ _TORCH_DEVICE_MAP = {
...
@@ -76,5 +93,5 @@ _TORCH_DEVICE_MAP = {
_infinicore
.
Device
.
Type
.
MOORE
:
"musa"
,
_infinicore
.
Device
.
Type
.
MOORE
:
"musa"
,
_infinicore
.
Device
.
Type
.
ILUVATAR
:
"cuda"
,
_infinicore
.
Device
.
Type
.
ILUVATAR
:
"cuda"
,
_infinicore
.
Device
.
Type
.
KUNLUN
:
"cuda"
,
_infinicore
.
Device
.
Type
.
KUNLUN
:
"cuda"
,
_infinicore
.
Device
.
Type
.
SU
GON
:
"cuda"
,
_infinicore
.
Device
.
Type
.
HY
GON
:
"cuda"
,
}
}
python/infinicore/tensor.py
View file @
93e7d887
import
infinicore.device
import
infinicore.dtype
from
.
import
_infinicore
from
.
import
_infinicore
class
Tensor
:
class
Tensor
:
def
__init__
(
self
,
tensor
):
def
__init__
(
self
,
underlying
):
"""An internal method. Please do not use this directly."""
"""An internal method. Please do not use this directly."""
self
.
_underlying
=
tensor
self
.
_underlying
=
underlying
self
.
_dtype
=
infinicore
.
dtype
(
self
.
_underlying
.
dtype
)
self
.
_device
=
infinicore
.
device
.
_from_infinicore_device
(
self
.
_underlying
.
device
)
@
property
@
property
def
shape
(
self
):
def
shape
(
self
):
...
@@ -13,11 +22,11 @@ class Tensor:
...
@@ -13,11 +22,11 @@ class Tensor:
@
property
@
property
def
dtype
(
self
):
def
dtype
(
self
):
return
self
.
_
underlying
.
dtype
return
self
.
_dtype
@
property
@
property
def
device
(
self
):
def
device
(
self
):
return
self
.
_
underlying
.
device
return
self
.
_device
@
property
@
property
def
ndim
(
self
):
def
ndim
(
self
):
...
...
src/infinicore/device.cc
View file @
93e7d887
...
@@ -37,8 +37,8 @@ std::string Device::toString(const Type &type) {
...
@@ -37,8 +37,8 @@ std::string Device::toString(const Type &type) {
return
"ILUVATAR"
;
return
"ILUVATAR"
;
case
Type
::
KUNLUN
:
case
Type
::
KUNLUN
:
return
"KUNLUN"
;
return
"KUNLUN"
;
case
Type
::
SU
GON
:
case
Type
::
HY
GON
:
return
"
SU
GON"
;
return
"
HY
GON"
;
}
}
// TODO: Add error handling.
// TODO: Add error handling.
...
...
src/infinicore/pybind11/device.hpp
View file @
93e7d887
...
@@ -20,7 +20,7 @@ inline void bind(py::module &m) {
...
@@ -20,7 +20,7 @@ inline void bind(py::module &m) {
.
value
(
"MOORE"
,
Device
::
Type
::
MOORE
)
.
value
(
"MOORE"
,
Device
::
Type
::
MOORE
)
.
value
(
"ILUVATAR"
,
Device
::
Type
::
ILUVATAR
)
.
value
(
"ILUVATAR"
,
Device
::
Type
::
ILUVATAR
)
.
value
(
"KUNLUN"
,
Device
::
Type
::
KUNLUN
)
.
value
(
"KUNLUN"
,
Device
::
Type
::
KUNLUN
)
.
value
(
"
SU
GON"
,
Device
::
Type
::
SU
GON
)
.
value
(
"
HY
GON"
,
Device
::
Type
::
HY
GON
)
.
value
(
"COUNT"
,
Device
::
Type
::
COUNT
);
.
value
(
"COUNT"
,
Device
::
Type
::
COUNT
);
device
device
...
...
src/infinicore/pybind11/tensor.hpp
View file @
93e7d887
...
@@ -15,6 +15,7 @@ inline void bind(py::module &m) {
...
@@ -15,6 +15,7 @@ inline void bind(py::module &m) {
.
def_property_readonly
(
"strides"
,
[](
const
Tensor
&
tensor
)
{
return
tensor
->
strides
();
})
.
def_property_readonly
(
"strides"
,
[](
const
Tensor
&
tensor
)
{
return
tensor
->
strides
();
})
.
def_property_readonly
(
"ndim"
,
[](
const
Tensor
&
tensor
)
{
return
tensor
->
ndim
();
})
.
def_property_readonly
(
"ndim"
,
[](
const
Tensor
&
tensor
)
{
return
tensor
->
ndim
();
})
.
def_property_readonly
(
"dtype"
,
[](
const
Tensor
&
tensor
)
{
return
tensor
->
dtype
();
})
.
def_property_readonly
(
"dtype"
,
[](
const
Tensor
&
tensor
)
{
return
tensor
->
dtype
();
})
.
def_property_readonly
(
"device"
,
[](
const
Tensor
&
tensor
)
{
return
tensor
->
device
();
})
.
def
(
"data_ptr"
,
[](
const
Tensor
&
tensor
)
{
return
tensor
->
data
();
})
.
def
(
"data_ptr"
,
[](
const
Tensor
&
tensor
)
{
return
tensor
->
data
();
})
.
def
(
"size"
,
[](
const
Tensor
&
tensor
,
std
::
size_t
dim
)
{
return
tensor
->
size
(
dim
);
})
.
def
(
"size"
,
[](
const
Tensor
&
tensor
,
std
::
size_t
dim
)
{
return
tensor
->
size
(
dim
);
})
...
...
test/infinicore/framework/devices.py
View file @
93e7d887
...
@@ -7,7 +7,7 @@ class InfiniDeviceEnum:
...
@@ -7,7 +7,7 @@ class InfiniDeviceEnum:
MOORE
=
5
MOORE
=
5
ILUVATAR
=
6
ILUVATAR
=
6
KUNLUN
=
7
KUNLUN
=
7
SU
GON
=
8
HY
GON
=
8
InfiniDeviceNames
=
{
InfiniDeviceNames
=
{
...
@@ -19,7 +19,7 @@ InfiniDeviceNames = {
...
@@ -19,7 +19,7 @@ InfiniDeviceNames = {
InfiniDeviceEnum
.
MOORE
:
"Moore"
,
InfiniDeviceEnum
.
MOORE
:
"Moore"
,
InfiniDeviceEnum
.
ILUVATAR
:
"Iluvatar"
,
InfiniDeviceEnum
.
ILUVATAR
:
"Iluvatar"
,
InfiniDeviceEnum
.
KUNLUN
:
"Kunlun"
,
InfiniDeviceEnum
.
KUNLUN
:
"Kunlun"
,
InfiniDeviceEnum
.
SU
GON
:
"
Su
gon"
,
InfiniDeviceEnum
.
HY
GON
:
"
Hy
gon"
,
}
}
# Mapping that maps InfiniDeviceEnum to torch device string
# Mapping that maps InfiniDeviceEnum to torch device string
...
@@ -32,5 +32,5 @@ torch_device_map = {
...
@@ -32,5 +32,5 @@ torch_device_map = {
InfiniDeviceEnum
.
MOORE
:
"musa"
,
InfiniDeviceEnum
.
MOORE
:
"musa"
,
InfiniDeviceEnum
.
ILUVATAR
:
"cuda"
,
InfiniDeviceEnum
.
ILUVATAR
:
"cuda"
,
InfiniDeviceEnum
.
KUNLUN
:
"cuda"
,
InfiniDeviceEnum
.
KUNLUN
:
"cuda"
,
InfiniDeviceEnum
.
SU
GON
:
"cuda"
,
InfiniDeviceEnum
.
HY
GON
:
"cuda"
,
}
}
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