Skip to content

[XPU] opt get_xpu_version to by caching output of Runtime #71697

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 18, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions paddle/phi/backends/xpu/xpu_info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License. */

#include <algorithm>
#include <cstdlib>
#include <mutex>
#include <string>

#include "glog/logging.h"
Expand Down Expand Up @@ -221,22 +222,25 @@ void MemcpySyncD2D(void* dst,
/**************************** Others **************************/

XPUVersion get_xpu_version(int dev_id) {
uint64_t v = 0;
if (dev_id == -1) {
dev_id = GetXPUCurrentDeviceId();
}
PADDLE_ENFORCE_XPU_SUCCESS(xpu_device_get_attr(&v, XPUATTR_MODEL, dev_id));

if (v == K100 || v == K200) {
VLOG(1) << "KUNLUN device " << dev_id << " is XPU1\n";
return XPU1;
} else if (v < KL3_BEGIN) {
VLOG(1) << "KUNLUN device " << dev_id << " is XPU2\n";
return XPU2;
} else {
VLOG(1) << "KUNLUN device " << dev_id << " is XPU3\n";
return XPU3;
thread_local std::unordered_map<int, XPUVersion> xpu_version_map;
if (xpu_version_map.count(dev_id) == 0) {
uint64_t v = 0;
PADDLE_ENFORCE_XPU_SUCCESS(xpu_device_get_attr(&v, XPUATTR_MODEL, dev_id));
if (v == K100 || v == K200) {
VLOG(1) << "KUNLUN device " << dev_id << " is XPU1\n";
xpu_version_map[dev_id] = XPU1;
} else if (v < KL3_BEGIN) {
VLOG(1) << "KUNLUN device " << dev_id << " is XPU2\n";
xpu_version_map[dev_id] = XPU2;
} else {
VLOG(1) << "KUNLUN device " << dev_id << " is XPU3\n";
xpu_version_map[dev_id] = XPU3;
}
}
return xpu_version_map[dev_id];
}

void set_xpu_debug_level(int level) {
Expand Down