Skip to content

[XPU] Failed to build libtorch program with XPUs #140877

@piDack

Description

@piDack

🐛 Describe the bug

I encountered an issue while attempting to build a libtorch program that utilizes XPUs. The build process terminated with errors, and I have not been able to resolve the issue despite following the available documentation and troubleshooting steps.
Below are my steps of operation:

  1. Download xpu backend torch 2.5.1 by pip
pip3 install torch --index-url https://download.pytorch.org/whl/test/xpu
  1. CMake
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
project(libtorch_trace)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
Set(Torch_DIR "<path>\\cmake\\Torch")
find_package(Torch REQUIRED)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORCH_CXX_FLAGS}"))
include_directories("C:/Users/Public/yhl/miniconda/envs/torchxpu/Lib/site-packages/torch/include/torch/csrc/api/include")
add_executable(${PROJECT_NAME} test.cpp)
target_link_libraries(${PROJECT_NAME} ${TORCH_LIBRARIES})
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 17)
  1. Cpp code
#include <torch/torch.h>
#include <iostream>
#include <chrono>
#include <thread>
#include <torch/xpu.h>

int main() {
  printf("xpu is alive %d\n",torch::xpu::is_available());
}

The error

CMake Error at C:/Users/Public/yhl/miniconda/envs/torchxpu/Lib/site-packages/torch/share/cmake/Caffe2/Caffe2Targets.cmake:106 (set_target_properties):
  The link interface of target "torch_xpu_library" contains:

    torch::xpurt

  but the target was not found.  Possible reasons include:

    * There is a typo in the target name.
    * A find_package call is missing for an IMPORTED target.
    * An ALIAS target is missing.

Call Stack (most recent call first):
  C:/Users/Public/yhl/miniconda/envs/torchxpu/Lib/site-packages/torch/share/cmake/Caffe2/Caffe2Config.cmake:114 (include)
  C:/Users/Public/yhl/miniconda/envs/torchxpu/Lib/site-packages/torch/share/cmake/Torch/TorchConfig.cmake:68 (find_package)
  CMakeLists.txt:8 (find_package)

I tried using CPU LibTorch with the aforementioned program and CMakeLists, and it works.How to fix it?

Versions

Collecting environment information...
PyTorch version: N/A
Is debug build: N/A
CUDA used to build PyTorch: N/A
ROCM used to build PyTorch: N/A

OS: Microsoft Windows 11 专业版 (10.0.26100 64 位)
GCC version: Could not collect
Clang version: Could not collect
CMake version: version 3.31.0
Libc version: N/A

Python version: 3.11.9 (tags/v3.11.9:de54cf5, Apr 2 2024, 10:12:12) [MSC v.1938 64 bit (AMD64)] (64-bit runtime)
Python platform: Windows-10-10.0.26100-SP0
Is CUDA available: N/A
CUDA runtime version: Could not collect
CUDA_MODULE_LOADING set to: N/A
GPU models and configuration: Could not collect
Nvidia driver version: Could not collect
cuDNN version: Could not collect
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: N/A

CPU:
Name: Intel(R) Core(TM) Ultra 9 288V
Manufacturer: GenuineIntel
Family: 775
Architecture: 9
ProcessorType: 3
DeviceID: CPU0
CurrentClockSpeed: 3300
MaxClockSpeed: 3300
L2CacheSize: 14336
L2CacheSpeed: None
Revision: None

Versions of relevant libraries:
[pip3] numpy==2.1.3
[pip3] optree==0.13.1
[pip3] torch==2.5.1+xpu
[conda] Could not collect

cc @jbschlosser @gujinghui @EikanWang @fengyuan14 @guangyey

Metadata

Metadata

Assignees

No one assigned

    Labels

    module: cppRelated to C++ APImodule: xpuIntel XPU related issuestriagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions