Skip to content

Commit 543e857

Browse files
gfxdev8jeffrey.yang
authored andcommitted
Add maca platform
1 parent cb54462 commit 543e857

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed

fastdeploy/platforms/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from .xpu import XPUPlatform
2323
from .npu import NPUPlatform
2424
from .dcu import DCUPlatform
25+
from .maca import MACAPlatform
2526
from .base import _Backend
2627

2728
_current_platform = None
@@ -34,6 +35,8 @@ def __getattr__(name: str):
3435
if _current_platform is None:
3536
if paddle.is_compiled_with_cuda():
3637
_current_platform = CUDAPlatform()
38+
elif paddle.is_compiled_with_custom_device("metax_gpu"):
39+
_current_platform = MACAPlatform()
3740
elif paddle.is_compiled_with_xpu():
3841
_current_platform = XPUPlatform()
3942
elif paddle.is_compiled_with_custom_device("npu"):

fastdeploy/platforms/base.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ def is_cuda(self) -> bool:
3333
whether platform is cuda
3434
"""
3535
return paddle.is_compiled_with_cuda()
36+
37+
def is_maca(self) -> bool:
38+
"""
39+
whether platform is maca
40+
"""
41+
return paddle.is_compiled_with_custom_device("metax_gpu")
3642

3743
def is_npu(self) -> bool:
3844
"""

fastdeploy/platforms/maca.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
"""
2+
# Copyright (c) 2025 MetaX-tech Authors. All Rights Reserved.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
"""
16+
17+
"""
18+
maca platform file
19+
"""
20+
21+
import paddle
22+
from .base import Platform, _Backend
23+
from paddlenlp.utils.log import logger
24+
25+
26+
class MACAPlatform(Platform):
27+
"""
28+
maca platform class
29+
"""
30+
device_name = "gpu"
31+
32+
@classmethod
33+
def available(self):
34+
"""
35+
Check whether MACA is available.
36+
"""
37+
try:
38+
assert len(paddle.static.cuda_places()) > 0
39+
return True
40+
except Exception as e:
41+
logger.warning(
42+
"You are using GPU version PaddlePaddle, but there is no GPU "
43+
"detected on your machine. Maybe CUDA devices is not set properly."
44+
f"\n Original Error is {e}"
45+
)
46+
return False
47+
48+
@classmethod
49+
def get_attention_backend_cls(
50+
cls,
51+
selected_backend
52+
):
53+
"""
54+
get_attention_backend_cls
55+
"""
56+
if selected_backend == _Backend.NATIVE_ATTN:
57+
logger.info("Using NATIVE ATTN backend.")
58+
return ("fastdeploy.model_executor.layers.attention.PaddleNativeAttnBackend")
59+
else:
60+
logger.warning(
61+
"Other backends are not supported for now."
62+
)

0 commit comments

Comments
 (0)