Skip to content

Commit

Permalink
add gpu whl (PaddlePaddle#9890)
Browse files Browse the repository at this point in the history
  • Loading branch information
bukejiyu authored Feb 20, 2025
1 parent 7ea4228 commit 347d77c
Show file tree
Hide file tree
Showing 10 changed files with 433 additions and 6 deletions.
40 changes: 40 additions & 0 deletions csrc/paddlenlp_ops/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import importlib

import paddle

from paddlenlp.utils.log import logger

cuda_version = float(paddle.version.cuda())
SUPPORTED_SM_VERSIONS = {70, 75, 80, 86, 89, 90} if cuda_version >= 12.4 else {70, 75, 80, 86, 89}


def get_sm_version():
prop = paddle.device.cuda.get_device_properties()
cc = prop.major * 10 + prop.minor
return cc


sm_version = get_sm_version()
if sm_version not in SUPPORTED_SM_VERSIONS:
raise RuntimeError("Unsupported SM version")
module_name = f"paddlenlp_ops.sm{sm_version}"

try:
module = importlib.import_module(module_name)
globals().update(vars(module))
except ImportError:
logger.WARNING(f"No {module_name} ")
20 changes: 20 additions & 0 deletions csrc/paddlenlp_ops/sm70/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from paddlenlp.utils.log import logger

try:
from .paddlenlp_ops_70 import *
except ImportError:
logger.WARNING("No paddlenlp_ops_70 ops")
20 changes: 20 additions & 0 deletions csrc/paddlenlp_ops/sm75/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from paddlenlp.utils.log import logger

try:
from .paddlenlp_ops_75 import *
except ImportError:
logger.WARNING("No paddlenlp_ops_75 ops")
20 changes: 20 additions & 0 deletions csrc/paddlenlp_ops/sm80/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from paddlenlp.utils.log import logger

try:
from .paddlenlp_ops_80 import *
except ImportError:
logger.WARNING("No paddlenlp_ops_80 ops")
20 changes: 20 additions & 0 deletions csrc/paddlenlp_ops/sm86/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from paddlenlp.utils.log import logger

try:
from .paddlenlp_ops_86 import *
except ImportError:
logger.WARNING("No paddlenlp_ops_86 ops")
20 changes: 20 additions & 0 deletions csrc/paddlenlp_ops/sm89/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from paddlenlp.utils.log import logger

try:
from .paddlenlp_ops_89 import *
except ImportError:
logger.WARNING("No paddlenlp_ops_89 ops")
20 changes: 20 additions & 0 deletions csrc/paddlenlp_ops/sm90/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from paddlenlp.utils.log import logger

try:
from .paddlenlp_ops_90 import *
except ImportError:
logger.WARNING("No paddlenlp_ops_90 ops")
73 changes: 73 additions & 0 deletions csrc/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

""" setup for EfficentLLM """

import os

from setuptools import find_packages, setup

description = "Paddlenlp_ops : inference framework implemented based on PaddlePaddle"
VERSION = "0.0.0"


def read(file: str):
"""
read file and return content
"""
current_dir = os.path.dirname(__file__)
path = os.path.join(current_dir, file)
with open(path, "r", encoding="utf-8") as f:
content = f.read().strip()
return content


def read_version():
"""
read version and return content
"""
return VERSION


def read_readme():
"""
read README.md and return content
"""
return read("README.md")


setup(
name="paddlenlp_ops",
packages=find_packages(),
version="0.0.0",
author="Paddle Infernce Team",
author_email="[email protected]",
description=description,
long_description=read_readme(),
long_description_content_type="text/markdown",
url="",
python_requires=">=3.8",
package_dir={"paddlenlp_ops": "paddlenlp_ops/"},
package_data={"paddlenlp_ops": ["sm70/*", "sm75/*", "sm80/*", "sm86/*", "sm89/*", "sm90/*"]},
include_package_data=True,
classifiers=[
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"License :: OSI Approved :: Apache Software License",
"Operating System :: OS Independent",
],
license="Apache 2.0",
)
16 changes: 10 additions & 6 deletions csrc/setup_cuda.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import paddle
from paddle.utils.cpp_extension import CUDAExtension, setup

sm_version = int(os.getenv("CUDA_SM_VERSION", "0"))


def update_git_submodule():
try:
Expand All @@ -38,9 +40,12 @@ def find_end_files(directory, end_str):


def get_sm_version():
prop = paddle.device.cuda.get_device_properties()
cc = prop.major * 10 + prop.minor
return cc
if sm_version > 0:
return sm_version
else:
prop = paddle.device.cuda.get_device_properties()
cc = prop.major * 10 + prop.minor
return cc


def strtobool(v):
Expand Down Expand Up @@ -77,8 +82,6 @@ def get_gencode_flags():
gencode_flags = get_gencode_flags()
library_path = os.environ.get("LD_LIBRARY_PATH", "/usr/local/cuda/lib64")

sm_version = get_sm_version()

sources = [
"./gpu/save_with_output.cc",
"./gpu/set_value_by_flags.cu",
Expand Down Expand Up @@ -176,8 +179,9 @@ def get_gencode_flags():
"gpu/fp8_gemm_with_cutlass/fp8_fp8_fp8_dual_gemm.cu",
]

ops_name = f"paddlenlp_ops_{sm_version}" if sm_version != 0 else "paddlenlp_ops"
setup(
name="paddlenlp_ops",
name=ops_name,
ext_modules=CUDAExtension(
sources=sources,
extra_compile_args={"cxx": ["-O3"], "nvcc": nvcc_compile_args},
Expand Down
Loading

0 comments on commit 347d77c

Please sign in to comment.