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
e68048cc
Commit
e68048cc
authored
Mar 10, 2025
by
qinyiqun
Browse files
issue/87:增加沐曦平台的handle
parent
92ad2426
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
165 additions
and
1 deletion
+165
-1
src/infiniop/devices/handle.cc
src/infiniop/devices/handle.cc
+9
-0
src/infiniop/devices/maca/common_maca.h
src/infiniop/devices/maca/common_maca.h
+27
-0
src/infiniop/devices/maca/maca_handle.cc
src/infiniop/devices/maca/maca_handle.cc
+62
-0
src/infiniop/devices/maca/maca_handle.h
src/infiniop/devices/maca/maca_handle.h
+24
-0
xmake.lua
xmake.lua
+2
-1
xmake/maca.lua
xmake/maca.lua
+41
-0
No files found.
src/infiniop/devices/handle.cc
View file @
e68048cc
...
...
@@ -17,6 +17,9 @@
#ifdef ENABLE_KUNLUN_API
#include "kunlun/kunlun_handle.h"
#endif
#ifdef ENABLE_MACA_API
#include "maca/maca_handle.h"
#endif
__C
infiniStatus_t
infiniopCreateHandle
(
infiniopHandle_t
*
handle_ptr
)
{
if
(
handle_ptr
==
nullptr
)
{
...
...
@@ -53,6 +56,9 @@ __C infiniStatus_t infiniopCreateHandle(infiniopHandle_t *handle_ptr) {
return
createKunlunHandle
((
infiniopKunlunHandle_t
*
)
handle_ptr
);
}
#endif
#ifdef ENABLE_MACA_API
CREATE
(
INFINI_DEVICE_METAX
,
maca
);
#endif
default:
return
INFINI_STATUS_DEVICE_TYPE_NOT_SUPPORTED
;
...
...
@@ -89,6 +95,9 @@ __C infiniStatus_t infiniopDestroyHandle(infiniopHandle_t handle) {
case
INFINI_DEVICE_KUNLUN
:
{
return
destroyKunlunHandle
((
infiniopKunlunHandle_t
)
handle
);
}
#endif
#ifdef ENABLE_MACA_API
DELETE
(
INFINI_DEVICE_METAX
,
maca
);
#endif
default:
return
INFINI_STATUS_DEVICE_TYPE_NOT_SUPPORTED
;
...
...
src/infiniop/devices/maca/common_maca.h
0 → 100644
View file @
e68048cc
#include "../../../utils.h"
#include "../pool.h"
#include "maca_handle.h"
#include <hcblas/hcblas.h>
#include <hcdnn/hcdnn.h>
#include <memory>
#define CHECK_MCBLAS(API) CHECK_INTERNAL(API, HCBLAS_STATUS_SUCCESS)
#define CHECK_MCDNN(API) CHECK_INTERNAL(API, HCDNN_STATUS_SUCCESS)
namespace
device
::
maca
{
class
Handle
::
Internal
{
Pool
<
hcblasHandle_t
>
mcblas_handles
;
Pool
<
hcdnnHandle_t
>
mcdnn_handles
;
template
<
typename
T
>
using
Fn
=
std
::
function
<
infiniStatus_t
(
T
)
>
;
public:
infiniStatus_t
use_mcblas
(
hcStream_t
stream
,
const
Fn
<
hcblasHandle_t
>
&
f
)
const
;
infiniStatus_t
use_mcdnn
(
hcStream_t
stream
,
const
Fn
<
hcdnnHandle_t
>
&
f
)
const
;
};
hcdnnDataType_t
getHcdnnDtype
(
infiniDtype_t
dt
);
}
// namespace device::maca
src/infiniop/devices/maca/maca_handle.cc
0 → 100644
View file @
e68048cc
#include "common_maca.h"
namespace
device
::
maca
{
Handle
::
Handle
(
infiniDevice_t
device
,
int
device_id
)
:
InfiniopHandle
{
device
,
device_id
},
_internal
(
std
::
make_shared
<
Handle
::
Internal
>
())
{}
auto
Handle
::
internal
()
const
->
const
std
::
shared_ptr
<
Internal
>
&
{
return
_internal
;
}
infiniStatus_t
Handle
::
Internal
::
use_mcblas
(
hcStream_t
stream
,
const
Fn
<
hcblasHandle_t
>
&
f
)
const
{
auto
handle
=
mcblas_handles
.
pop
();
if
(
!
handle
)
{
CHECK_MCBLAS
(
hcblasCreate
(
&
(
*
handle
)));
}
CHECK_MCBLAS
(
hcblasSetStream
(
*
handle
,
stream
));
CHECK_STATUS
(
f
(
*
handle
));
mcblas_handles
.
push
(
std
::
move
(
*
handle
));
return
INFINI_STATUS_SUCCESS
;
}
infiniStatus_t
Handle
::
Internal
::
use_mcdnn
(
hcStream_t
stream
,
const
Fn
<
hcdnnHandle_t
>
&
f
)
const
{
auto
handle
=
mcdnn_handles
.
pop
();
if
(
!
handle
)
{
CHECK_MCDNN
(
hcdnnCreate
(
&
(
*
handle
)));
}
CHECK_MCDNN
(
hcdnnSetStream
(
*
handle
,
stream
));
CHECK_STATUS
(
f
(
*
handle
));
mcdnn_handles
.
push
(
std
::
move
(
*
handle
));
return
INFINI_STATUS_SUCCESS
;
}
hcdnnDataType_t
getHcdnnDtype
(
infiniDtype_t
dt
)
{
switch
(
dt
)
{
case
INFINI_DTYPE_F16
:
return
HCDNN_DATA_HALF
;
case
INFINI_DTYPE_F32
:
return
HCDNN_DATA_FLOAT
;
case
INFINI_DTYPE_F64
:
return
HCDNN_DATA_DOUBLE
;
case
INFINI_DTYPE_BF16
:
return
HCDNN_DATA_BFLOAT16
;
case
INFINI_DTYPE_I8
:
return
HCDNN_DATA_INT8
;
case
INFINI_DTYPE_I32
:
return
HCDNN_DATA_INT32
;
case
INFINI_DTYPE_I64
:
return
HCDNN_DATA_INT64
;
case
INFINI_DTYPE_U8
:
return
HCDNN_DATA_UINT8
;
default:
return
HCDNN_DATA_FLOAT
;
}
}
infiniStatus_t
Handle
::
create
(
InfiniopHandle
**
handle_ptr
,
int
device_id
)
{
*
handle_ptr
=
new
Handle
(
INFINI_DEVICE_METAX
,
device_id
);
return
INFINI_STATUS_SUCCESS
;
}
}
// namespace device::maca
src/infiniop/devices/maca/maca_handle.h
0 → 100644
View file @
e68048cc
#ifndef __INFINIOP_MACA_HANDLE_H__
#define __INFINIOP_MACA_HANDLE_H__
#include "../../handle.h"
#include <memory>
namespace
device
::
maca
{
struct
Handle
:
public
InfiniopHandle
{
class
Internal
;
auto
internal
()
const
->
const
std
::
shared_ptr
<
Internal
>
&
;
public:
static
infiniStatus_t
create
(
InfiniopHandle
**
handle_ptr
,
int
device_id
);
protected:
Handle
(
infiniDevice_t
device
,
int
device_id
);
private:
std
::
shared_ptr
<
Internal
>
_internal
;
};
}
// namespace device::maca
#endif // __INFINIOP_MACA_HANDLE_H__
xmake.lua
View file @
e68048cc
...
...
@@ -75,6 +75,7 @@ option_end()
if
has_config
(
"metax-gpu"
)
then
add_defines
(
"ENABLE_MACA_API"
)
includes
(
"xmake/maca.lua"
)
end
-- 摩尔线程
...
...
@@ -169,7 +170,7 @@ target("infiniop")
add_deps
(
"infiniop-ascend"
)
end
if
has_config
(
"metax-gpu"
)
then
add_deps
(
"metax
-gpu
"
)
add_deps
(
"
infiniop-
metax"
)
end
if
has_config
(
"kunlun-xpu"
)
then
add_deps
(
"infiniop-kunlun"
)
...
...
xmake/maca.lua
0 → 100644
View file @
e68048cc
local
MACA_ROOT
=
os.getenv
(
"MACA_PATH"
)
or
os.getenv
(
"MACA_HOME"
)
or
os.getenv
(
"MACA_ROOT"
)
add_includedirs
(
MACA_ROOT
..
"/include"
)
add_linkdirs
(
MACA_ROOT
..
"/lib"
)
add_links
(
"libhcdnn.so"
)
add_links
(
"libhcblas.so"
)
add_links
(
"libhcruntime.so"
)
rule
(
"maca"
)
set_extensions
(
".maca"
)
on_load
(
function
(
target
)
target
:
add
(
"includedirs"
,
"include"
)
end
)
on_build_file
(
function
(
target
,
sourcefile
)
local
objectfile
=
target
:
objectfile
(
sourcefile
)
os
.
mkdir
(
path
.
directory
(
objectfile
))
local
htcc
=
path
.
join
(
MACA_ROOT
,
"htgpu_llvm/bin/htcc"
)
local
includedirs
=
table.concat
(
target
:
get
(
"includedirs"
),
" "
)
local
args
=
{
"-x"
,
"hpcc"
,
"-c"
,
sourcefile
,
"-o"
,
objectfile
,
"-I"
..
MACA_ROOT
..
"/include"
,
"-O3"
,
"-fPIC"
,
"-Werror"
,
"-std=c++17"
}
for
_
,
includedir
in
ipairs
(
target
:
get
(
"includedirs"
))
do
table.insert
(
args
,
"-I"
..
includedir
)
end
os
.
execv
(
htcc
,
args
)
table.insert
(
target
:
objectfiles
(),
objectfile
)
end
)
rule_end
()
target
(
"infiniop-metax"
)
set_kind
(
"static"
)
on_install
(
function
(
target
)
end
)
set_languages
(
"cxx17"
)
add_files
(
"../src/infiniop/devices/maca/*.cc"
,
"../src/infiniop/ops/*/maca/*.cc"
)
add_files
(
"../src/infiniop/ops/*/maca/*.maca"
,
{
rule
=
"maca"
})
add_cxflags
(
"-lstdc++ -Werror -fPIC"
)
target_end
()
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