Skip to content
Open
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<Import Project="build/Dependencies.props" />

<PropertyGroup>
<CustomLibTorchFullPath></CustomLibTorchFullPath>
<Configuration Condition="'$(Configuration)'==''">Debug</Configuration>
<Configurations>Debug;Release</Configurations>
<_DefaultArchitecture>$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture.ToString().ToLower())</_DefaultArchitecture>
Expand Down Expand Up @@ -167,6 +168,9 @@
<DefineConstants>$(DefineContants);DEBUG</DefineConstants>
<Optimize>false</Optimize>
</PropertyGroup>
<PropertyGroup Condition="'$(NativeTargetArchitecture)' == 'x64' and '$(SkipCuda)' != 'true' and '$(SkipNative)' != 'true'">
<DefineConstants>$(DefineContants);CUDA_TOOLKIT_FOUND</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="$(Configuration.StartsWith('Release'))">
<Optimize>true</Optimize>
</PropertyGroup>
Expand Down
1 change: 1 addition & 0 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
<NativeAssemblyReference Include="gomp-98b21ff3" ExtraExtension=".1" />
</ItemGroup>


<Target Name="CopyNativeAssemblies"
BeforeTargets="PrepareForRun"
Condition="'$(SkipTests)' != 'true'">
Expand Down
4 changes: 2 additions & 2 deletions pkg/pack.proj
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Project>
<Import Project="..\Directory.Build.props" />
<ItemGroup>

<ItemGroup Condition="$(CustomLibTorchFullPath)==''">
<PackProject Include="**\libtorch-cpu.nupkgproj" Condition="'$(IncludeLibTorchCpuPackages)' == 'true'" />
<PackProject Include="**\libtorch-cpu-*.nupkgproj" Condition="'$(IncludeLibTorchCpuPackages)' == 'true'" />
<PackProject Include="**\libtorch-cuda-$(CudaVersionDot)-linux-*.nupkgproj" Condition="'$(IncludeLibTorchCudaPackages)' == 'true' AND '$(TargetOS)' == 'linux'" />
Expand Down Expand Up @@ -29,5 +30,4 @@

<Message Text="Done packing!" Importance="high" />
</Target>

</Project>
11 changes: 11 additions & 0 deletions src/Native/LibTorchSharp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
project(LibTorchSharp)

find_package(CUDA QUIET)
if(CUDA_FOUND)
include_directories(${CUDA_INCLUDE_DIRS})
link_directories(${CUDA_LIBRARY_DIRS})
add_compile_definitions(TORCHSHARP_CUDA_TOOLKIT_FOUND)
endif()

if(APPLE AND NOT LIBTORCH_ARCH STREQUAL "arm64")
include_directories("/usr/local/include" "/usr/local/opt/llvm/include")
link_directories("/usr/local/lib" "/usr/local/opt/llvm/lib")
Expand Down Expand Up @@ -70,6 +77,10 @@ include_directories(${TORCH_INCLUDE_DIRS})

add_library(LibTorchSharp SHARED ${SOURCES} ${RESOURCES})

if(CUDA_FOUND)
target_link_libraries(LibTorchSharp ${CUDA_LIBRARIES})
endif()

target_link_libraries(LibTorchSharp ${TORCH_LIBRARIES})

set_property(TARGET LibTorchSharp PROPERTY CXX_STANDARD 14)
Expand Down
9 changes: 6 additions & 3 deletions src/Native/build.proj
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,20 @@
<Target Name="BuildNativeWindows"
Condition="'$(OS)' == 'Windows_NT'">

<PropertyGroup>
<PropertyGroup Condition="$(CustomLibTorchFullPath)==''">
<BuildArgs>$(NativeConfiguration) $(TargetArchitecture) --libtorchpath $(LibTorchCmakePath)</BuildArgs>
</PropertyGroup>

<PropertyGroup Condition="$(CustomLibTorchFullPath)!=''">
<!--<CustomLibTorchFullPath>$(CustomLibTorchFullPath)\libtorch\share\cmake\Torch</CustomLibTorchFullPath>-->
<BuildArgs>$(NativeConfiguration) $(TargetArchitecture) --libtorchpath $(CustomLibTorchFullPath)</BuildArgs>
</PropertyGroup>
<!-- Run script that invokes Cmake to create VS files, and then calls msbuild to compile them -->
<Message Text="$(MSBuildProjectDirectory)\build.cmd $(BuildArgs)" Importance="High"/>
<Exec Command="&quot;$(MSBuildProjectDirectory)\build.cmd&quot; $(BuildArgs)" />

</Target>

<Target Name="PreparePackageAssets">
<Target Name="PreparePackageAssets" Condition="'$(CustomLibTorchFullPath)'==''">

<ItemGroup>
<NativePackageAsset Include="$(NativeOutputPath)$(NativeLibPrefix)LibTorchSharp$(NativeLibExtension)"
Expand Down
21 changes: 11 additions & 10 deletions src/TorchSharp/Tensor/torch.OtherOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -437,33 +437,34 @@ public static Tensor einsum(string equation, params Tensor[] tensors)

// https://pytorch.org/docs/stable/generated/torch.histogram
[Obsolete("not implemented", true)]
static Tensor histogram(
Tensor input,
static Tensor histogram(Tensor input,
long bins,
(float min, float max)? range = null,
Tensor? weight = null,
bool density = false)
=> throw new NotImplementedException();
bool density = false)=> throw new NotImplementedException();

// https://pytorch.org/docs/stable/generated/torch.histogram
[Obsolete("not implemented", true)]
static Tensor histogram(
Tensor input,
static Tensor histogram(Tensor input,
long[] bins,
(float min, float max)? range = null,
Tensor? weight = null,
bool density = false)
=> throw new NotImplementedException();
{
throw new NotImplementedException();
}


// https://pytorch.org/docs/stable/generated/torch.histogram
[Obsolete("not implemented", true)]
static Tensor histogram(
Tensor input,
static Tensor histogram(Tensor input,
Tensor[] bins,
(float min, float max)? range = null,
Tensor? weight = null,
bool density = false)
=> throw new NotImplementedException();
{
throw new NotImplementedException();
}

// https://pytorch.org/docs/stable/generated/torch.histogramdd
[Obsolete("not implemented", true)]
Expand Down
12 changes: 8 additions & 4 deletions src/TorchSharp/TorchSharp.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project>
<Project>
<!-- Implicit top import -->
<Import Project="Sdk.props" Sdk="Microsoft.NET.Sdk" />

Expand All @@ -11,6 +11,7 @@
<UseStyleCopAnalyzer>false</UseStyleCopAnalyzer>
<IsPackable>false</IsPackable>
<DefineConstants>$(DefineConstants);LIBTORCH_$(LibTorchPackageVersion.Replace('.', '_'));CUDA_$(CudaVersionDot.Replace('.', '_'))</DefineConstants>
<CustomLibTorchFullPath></CustomLibTorchFullPath>
</PropertyGroup>

<ItemGroup>
Expand Down Expand Up @@ -61,7 +62,8 @@
<Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" />

<!-- Trigger the download+placement of the redist bits and the build of the C++ project -->
<Target Name="BuildNativeLibTorch" BeforeTargets="BeforeBuild">

<Target Name="BuildNativeLibTorch" BeforeTargets="BeforeBuild" Condition="$(CustomLibTorchFullPath) == ''">
<Message Importance="High" Text="Using VersionSuffix = $(VersionSuffix)" />
<Message Importance="High" Text="Using Version = $(Version)" />
<MSBuild Projects="..\Redist\libtorch-cuda-$(CudaVersionDot)\libtorch-cuda-$(CudaVersionDot).proj" Condition="'$(BuildingInsideVisualStudio)'!='true' AND '$(SkipNative)' != 'true' AND '$(SkipCuda)' != 'true'" RemoveProperties="TargetFramework" Targets="Build" />
Expand All @@ -70,8 +72,10 @@

<MSBuild Projects="..\Native\build.proj" Condition="'$(SkipNative)' != 'true'" RemoveProperties="TargetFramework" Targets="Build" />
</Target>

<Target Name="RealPack">
<Target Name="BuildNativeLibTorch" BeforeTargets="BeforeBuild">
<MSBuild Projects="..\Native\build.proj" Condition="'$(SkipNative)' != 'true'" RemoveProperties="TargetFramework" Targets="Build" />
</Target>
<Target Name="RealPack" Condition="$(CustomLibTorchFullPath) == ''">
<MSBuild Projects="..\..\pkg\pack.proj" Targets="Pack" />
</Target>

Expand Down
2 changes: 1 addition & 1 deletion test/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<TargetFrameworks Condition="'$(OS)' == 'Windows_NT'">$(TargetFrameworks);net48</TargetFrameworks>
<IsPackable>false</IsPackable>
<GenerateDocumentationFile>true</GenerateDocumentationFile>

<CustomLibTorchFullPath></CustomLibTorchFullPath>
<!--
Don't warn about missing documentation in test projects.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<UseStyleCopAnalyzer>false</UseStyleCopAnalyzer>
<VSTestLogger>trx</VSTestLogger>
<VSTestResultsDirectory>$(OutputPath)</VSTestResultsDirectory>
<CustomLibTorchFullPath></CustomLibTorchFullPath>
</PropertyGroup>

<ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions test/TorchSharpTest/TorchSharpTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<VSTestLogger>trx</VSTestLogger>
<VSTestResultsDirectory>$(OutputPath)</VSTestResultsDirectory>
<LangVersion>10.0</LangVersion>
<CustomLibTorchFullPath></CustomLibTorchFullPath>
</PropertyGroup>

<ItemGroup>
Expand Down