chore: import upstream snapshot with attribution

This commit is contained in:
wehub-resource-sync
2026-07-13 12:40:42 +08:00
commit e25996e7db
15472 changed files with 3536181 additions and 0 deletions
@@ -0,0 +1,58 @@
cmake_minimum_required(VERSION 3.10)
project(example LANGUAGES CXX)
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR x86_64)
set(CMAKE_C_COMPILER "gcc")
set(CMAKE_CXX_COMPILER "g++")
if(NOT DEFINED XDNN_PATH)
set(XDNN_PATH $ENV{XDNN_PATH})
endif()
if(NOT DEFINED XRE_PATH)
set(XRE_PATH $ENV{XRE_PATH})
endif()
if(NOT IS_DIRECTORY ${XDNN_PATH})
message(
FATAL_ERROR
"XDNN_PATH not set, or directory ${XDNN_PATH} not found, please export XDNN_PATH=<path_to_xdnn>."
)
endif()
if(NOT IS_DIRECTORY ${XRE_PATH})
message(
FATAL_ERROR
"XRE_PATH not set, or directory ${XRE_PATH} not found, please export XRE_PATH=<path_to_xre>."
)
endif()
set(XDNN_INC_DIR ${XDNN_PATH}/include)
set(XDNN_LIB_DIR ${XDNN_PATH}/so)
set(XRE_INC_DIR ${XRE_PATH}/include)
set(XRE_LIB_DIR ${XRE_PATH}/so)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wl,--allow-shlib-undefined")
include_directories(${XDNN_INC_DIR})
include_directories(${XRE_INC_DIR})
link_directories(${XDNN_LIB_DIR})
link_directories(${XRE_LIB_DIR})
set(DEPS ${DEPS} xpurt xpuapi)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../include)
if(NOT DEFINED LINK_TYPE)
set(LINK_TYPE $ENV{LINK_TYPE})
endif()
if(LINK_TYPE STREQUAL "static")
set(DEPS ${DEPS} ${CMAKE_CURRENT_SOURCE_DIR}/../build/libxpuplugin.a)
elseif(LINK_TYPE STREQUAL "shared")
link_directories(${CMAKE_CURRENT_SOURCE_DIR}/../build)
set(DEPS ${DEPS} xpuplugin)
else()
message(
FATAL_ERROR
"Unknown LINK_TYPE ${LINK_TYPE}, only supports static or shared.")
return()
endif()
add_executable(example example.cc)
target_link_libraries(example ${DEPS})
+27
View File
@@ -0,0 +1,27 @@
#!/bin/bash
# Copyright (c) 2023 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.
set -e
#export XDNN_PATH=/opt/xdnn # <path_to_xdnn>
#export XRE_PATH=/opt/xre # <path_to_xre>
export LINK_TYPE=static # shared/static
rm -rf build
mkdir build
cd build
cmake -DCMAKE_VERBOSE_MAKEFILE=ON ..
make
@@ -0,0 +1,71 @@
// Copyright (c) 2023 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.
/*
* copyright (C) 2022 KUNLUNXIN, Inc
*/
#include <assert.h>
#include "xpu/plugin.h"
#include "xpu/xdnn.h"
namespace xdnn = baidu::xpu::api;
int main() {
int num = 5;
int errcode = 0;
auto ctx = xdnn::create_context();
float* A = nullptr;
errcode = xpu_malloc(reinterpret_cast<void**>(&A), num * sizeof(float));
assert(errcode == 0);
float* B = nullptr;
errcode = xpu_malloc(reinterpret_cast<void**>(&B), num * sizeof(float));
assert(errcode == 0);
std::vector<float> A_cpu = {1, 2, 3, 4, 5};
std::vector<float> B_cpu(num, 0.0f);
std::vector<float> B_ref = {3, 4, 5, 6, 7};
xpu_memcpy(reinterpret_cast<void*>(A),
reinterpret_cast<void*>(&(A_cpu[0])),
num * sizeof(float),
XPUMemcpyKind::XPU_HOST_TO_DEVICE);
errcode = xdnn::plugin::add2(ctx, A, B, num);
assert(errcode == 0);
xpu_memcpy(reinterpret_cast<void*>(&(B_cpu[0])),
reinterpret_cast<void*>(B),
num * sizeof(float),
XPUMemcpyKind::XPU_DEVICE_TO_HOST);
printf("A(%p):\n", A);
for (size_t i = 0; i < num; i++) {
printf("%f ", A_cpu[i]);
}
printf("\nB(%p):\n", B);
for (size_t i = 0; i < num; i++) {
printf("%f ", B_cpu[i]);
}
bool pass = true;
for (size_t i = 0; i < num; i++) {
if (fabs(B_cpu[i] - B_ref[i]) > 1e-5f) {
pass = false;
break;
}
}
printf("\nCheck %s! \n", pass ? "pass" : "fail");
destroy_context(ctx);
errcode = xpu_free(A);
assert(errcode == 0);
errcode = xpu_free(B);
assert(errcode == 0);
return 0;
}
+59
View File
@@ -0,0 +1,59 @@
#!/bin/bash
# Copyright (c) 2023 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.
set -e
#XDNN_PATH=/opt/xdnn # <path_to_xdnn>
#XRE_PATH=/opt/xre # <path_to_xre>
if [[ "$XDNN_PATH" == "" ]] || [[ ! -d "$XDNN_PATH" ]]; then
echo "XDNN_PATH not set, or directory ${XDNN_PATH} not found, please export XDNN_PATH=<path_to_xdnn>."
exit -1
fi
if [[ "$XRE_PATH" == "" ]] || [[ ! -d "$XRE_PATH" ]]; then
echo "XRE_PATH not set, or directory ${XRE_PATH} not found, please export XRE_PATH=<path_to_xre>."
exit -1
fi
#:<<!
export GLOG_v=0
export XPU_VISIBLE_DEVICES=0;
export XPUAPI_DEBUG=1;
export LD_LIBRARY_PATH=$XDNN_PATH/so:$XRE_PATH/so:$LD_LIBRARY_PATH
chmod +x ./build/example
./build/example
#!
:<<!
SSH_IP_ADDR=localhost
SSH_PORT=9031
SSH_USR_ID=root
SSH_USR_PWD=root
WORK_SPACE="/var/tmp/example"
EXPORT_ENVIRONMENT_VARIABLES="export GLOG_v=0;export XPU_VISIBLE_DEVICES=0;export XPUAPI_DEBUG=1;"
EXPORT_ENVIRONMENT_VARIABLES="${EXPORT_ENVIRONMENT_VARIABLES}export LD_LIBRARY_PATH=.:\$LD_LIBRARY_PATH;"
sshpass -p $SSH_USR_PWD ssh -v -o ConnectTimeout=60 -o StrictHostKeyChecking=no -p $SSH_PORT $SSH_USR_ID@$SSH_IP_ADDR "rm -rf $WORK_SPACE"
sshpass -p $SSH_USR_PWD ssh -v -o ConnectTimeout=60 -o StrictHostKeyChecking=no -p $SSH_PORT $SSH_USR_ID@$SSH_IP_ADDR "mkdir -p $WORK_SPACE"
sshpass -p $SSH_USR_PWD scp -v -r -o ConnectTimeout=60 -o StrictHostKeyChecking=no -P $SSH_PORT $XDNN_PATH/so/* $SSH_USR_ID@$SSH_IP_ADDR:$WORK_SPACE
sshpass -p $SSH_USR_PWD scp -v -r -o ConnectTimeout=60 -o StrictHostKeyChecking=no -P $SSH_PORT $XRE_PATH/so/* $SSH_USR_ID@$SSH_IP_ADDR:$WORK_SPACE
sshpass -p $SSH_USR_PWD scp -v -r -o ConnectTimeout=60 -o StrictHostKeyChecking=no -P $SSH_PORT ../build/libxpuplugin.so $SSH_USR_ID@$SSH_IP_ADDR:$WORK_SPACE
sshpass -p $SSH_USR_PWD scp -v -r -o ConnectTimeout=60 -o StrictHostKeyChecking=no -P $SSH_PORT build/example $SSH_USR_ID@$SSH_IP_ADDR:$WORK_SPACE
sshpass -p $SSH_USR_PWD ssh -v -o ConnectTimeout=60 -o StrictHostKeyChecking=no -p $SSH_PORT $SSH_USR_ID@$SSH_IP_ADDR "cd $WORK_SPACE; ${EXPORT_ENVIRONMENT_VARIABLES} chmod +x ./example; ./example"
!