While trying to get libtorch working with my UE5.5 project, whenever I am trying to upload a Tensor to gpu, this error pops up PyTorch is not linked with support for cuda devices
.
After some research i found that it was the same problem with:
#ifdef _MSC_VER
constexpr const char* CUDA_HELP =
"PyTorch splits its backend into two shared libraries: a CPU library "
"and a CUDA library; this error has occurred because you are trying "
"to use some CUDA functionality, but the CUDA library has not been "
"loaded by the dynamic linker for some reason. The CUDA library MUST "
"be loaded, EVEN IF you don't directly use any symbols from the CUDA library! "
"One common culprit is a lack of -INCLUDE:?warp_size@cuda@at@@YAHXZ "
"in your link arguments; many dynamic linkers will delete dynamic library "
"dependencies if you don't depend on any of their symbols. You can check "
"if this has occurred by using link on your binary to see if there is a "
"dependency on *_cuda.dll library.";
#else
constexpr const char* CUDA_HELP =
"PyTorch splits its backend into two shared libraries: a CPU library "
"and a CUDA library; this error has occurred because you are trying "
"to use some CUDA functionality, but the CUDA library has not been "
"loaded by the dynamic linker for some reason. The CUDA library MUST "
"be loaded, EVEN IF you don't directly use any symbols from the CUDA library! "
"One common culprit is a lack of -Wl,--no-as-needed in your link arguments; many "
"dynamic linkers will delete dynamic library dependencies if you don't "
"depend on any of their symbols. You can check if this has occurred by "
"using ldd on your binary to see if there is a dependency on *_cuda.so "
"library.";
#endif
which could be found in torch\ATen\detail\CUDAHooksInterface.h
.
I am now trying to add this linker flag to Unreal Build Tool where my MyProject.Target.cs
looking like:
// Copyright Epic Games, Inc. All Rights Reserved.
using UnrealBuildTool;
using System.Collections.Generic;
public class MyProjectTarget : TargetRules
{
public MyProjectTarget(TargetInfo Target) : base(Target)
{
Type = TargetType.Game;
DefaultBuildSettings = BuildSettingsVersion.V5;
IncludeOrderVersion = EngineIncludeOrderVersion.Unreal5_5;
ExtraModuleNames.Add("MyProject");
if (AdditionalLinkerArguments is null)
AdditionalLinkerArguments = "/INCLUDE:?warp_size@cuda@at@@YAHXZ";
else
AdditionalLinkerArguments += " /INCLUDE:?warp_size@cuda@at@@YAHXZ";
}
}
But this seems to do nothing, and there is nothing related with this line in the Intermediate
folder too. Could somebody kindly give me some hint?
I am using the latest libtorch from libtorch-win-shared-with-deps-2.7.0+cu118.zip
.