Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
torch-scatter
Commits
f1c4e124
Unverified
Commit
f1c4e124
authored
Apr 18, 2020
by
Matthias Fey
Committed by
GitHub
Apr 18, 2020
Browse files
Merge pull request #134 from rusty1s/c_api
cmake
parents
1eef2be1
fcc44d7a
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
180 additions
and
0 deletions
+180
-0
CMakeLists.txt
CMakeLists.txt
+68
-0
README.md
README.md
+13
-0
cmake/TorchScatterConfig.cmake.in
cmake/TorchScatterConfig.cmake.in
+38
-0
csrc/scatter.h
csrc/scatter.h
+61
-0
No files found.
CMakeLists.txt
0 → 100644
View file @
f1c4e124
cmake_minimum_required
(
VERSION 3.0
)
project
(
torchscatter
)
set
(
CMAKE_CXX_STANDARD 14
)
set
(
TORCHSCATTER_VERSION 2.0.4
)
option
(
WITH_CUDA
"Enable CUDA support"
OFF
)
if
(
WITH_CUDA
)
enable_language
(
CUDA
)
add_definitions
(
-D__CUDA_NO_HALF_OPERATORS__
)
endif
()
find_package
(
Python3 COMPONENTS Development
)
find_package
(
Torch REQUIRED
)
file
(
GLOB HEADERS csrc/scatter.h
)
file
(
GLOB OPERATOR_SOURCES csrc/cpu/*.h csrc/cpu/*.cpp csrc/*.cpp
)
if
(
WITH_CUDA
)
file
(
GLOB OPERATOR_SOURCES
${
OPERATOR_SOURCES
}
csrc/cuda/*.h csrc/cuda/*.cu
)
endif
()
add_library
(
${
PROJECT_NAME
}
SHARED
${
OPERATOR_SOURCES
}
)
target_link_libraries
(
${
PROJECT_NAME
}
PRIVATE
${
TORCH_LIBRARIES
}
Python3::Python
)
set_target_properties
(
${
PROJECT_NAME
}
PROPERTIES EXPORT_NAME TorchScatter
)
target_include_directories
(
${
PROJECT_NAME
}
INTERFACE
$<BUILD_INTERFACE:
${
HEADERS
}
>
$<INSTALL_INTERFACE:
${
CMAKE_INSTALL_INCLUDEDIR
}
>
)
include
(
GNUInstallDirs
)
include
(
CMakePackageConfigHelpers
)
set
(
TORCHSCATTER_CMAKECONFIG_INSTALL_DIR
"share/cmake/TorchScatter"
CACHE STRING
"install path for TorchScatterConfig.cmake"
)
configure_package_config_file
(
cmake/TorchScatterConfig.cmake.in
"
${
CMAKE_CURRENT_BINARY_DIR
}
/TorchScatterConfig.cmake"
INSTALL_DESTINATION
${
TORCHSCATTER_CMAKECONFIG_INSTALL_DIR
}
)
write_basic_package_version_file
(
${
CMAKE_CURRENT_BINARY_DIR
}
/TorchScatterConfigVersion.cmake
VERSION
${
TORCHSCATTER_VERSION
}
COMPATIBILITY AnyNewerVersion
)
install
(
FILES
${
CMAKE_CURRENT_BINARY_DIR
}
/TorchScatterConfig.cmake
${
CMAKE_CURRENT_BINARY_DIR
}
/TorchScatterConfigVersion.cmake
DESTINATION
${
TORCHSCATTER_CMAKECONFIG_INSTALL_DIR
}
)
install
(
TARGETS
${
PROJECT_NAME
}
EXPORT TorchScatterTargets
LIBRARY DESTINATION
${
CMAKE_INSTALL_LIBDIR
}
)
install
(
EXPORT TorchScatterTargets
NAMESPACE TorchScatter::
DESTINATION
${
TORCHSCATTER_CMAKECONFIG_INSTALL_DIR
}
)
install
(
FILES
${
HEADERS
}
DESTINATION
${
CMAKE_INSTALL_INCLUDEDIR
}
/
${
PROJECT_NAME
}
)
install
(
FILES
csrc/cpu/scatter_cpu.h
csrc/cpu/segment_coo_cpu.h
csrc/cpu/segment_csr_cpu.h
DESTINATION
${
CMAKE_INSTALL_INCLUDEDIR
}
/
${
PROJECT_NAME
}
/cpu
)
if
(
WITH_CUDA
)
install
(
FILES
csrc/cpu/scatter_cuda.h
csrc/cpu/segment_coo_cuda.h
csrc/cpu/segment_csr_cuda.h
DESTINATION
${
CMAKE_INSTALL_INCLUDEDIR
}
/
${
PROJECT_NAME
}
/cuda
)
endif
()
README.md
View file @
f1c4e124
...
...
@@ -110,3 +110,16 @@ tensor([[5, 5, 3, 4, 0, 1]
```
python setup.py test
```
## C++ API
`torch-scatter`
also offers a C++ API that contains C++ equivalent of python models.
```
mkdir build
cd build
# Add -DWITH_CUDA=on support for the CUDA if needed
cmake ..
make
make install
```
cmake/TorchScatterConfig.cmake.in
0 → 100644
View file @
f1c4e124
# TorchScatterConfig.cmake
# --------------------
#
# Exported targets:: Scatter
#
@PACKAGE_INIT@
set(PN TorchScatter)
set(${PN}_INCLUDE_DIR "${PACKAGE_PREFIX_DIR}/@CMAKE_INSTALL_INCLUDEDIR@")
set(${PN}_LIBRARY "")
set(${PN}_DEFINITIONS USING_${PN})
check_required_components(${PN})
if(NOT (CMAKE_VERSION VERSION_LESS 3.0))
#-----------------------------------------------------------------------------
# Don't include targets if this file is being picked up by another
# project which has already built this as a subproject
#-----------------------------------------------------------------------------
if(NOT TARGET ${PN}::TorchScatter)
include("${CMAKE_CURRENT_LIST_DIR}/${PN}Targets.cmake")
if(NOT TARGET torch_library)
find_package(Torch REQUIRED)
endif()
if(NOT TARGET Python3::Python)
find_package(Python3 COMPONENTS Development)
endif()
target_link_libraries(TorchScatter::TorchScatter INTERFACE ${TORCH_LIBRARIES} Python3::Python)
if(@WITH_CUDA@)
target_compile_definitions(TorchScatter::TorchScatter INTERFACE WITH_CUDA)
endif()
endif()
endif()
csrc/scatter.h
0 → 100644
View file @
f1c4e124
#pragma once
#include <torch/extension.h>
int64_t
cuda_version
();
torch
::
Tensor
scatter_sum
(
torch
::
Tensor
src
,
torch
::
Tensor
index
,
int64_t
dim
,
torch
::
optional
<
torch
::
Tensor
>
optional_out
,
torch
::
optional
<
int64_t
>
dim_size
);
torch
::
Tensor
scatter_mean
(
torch
::
Tensor
src
,
torch
::
Tensor
index
,
int64_t
dim
,
torch
::
optional
<
torch
::
Tensor
>
optional_out
,
torch
::
optional
<
int64_t
>
dim_size
);
std
::
tuple
<
torch
::
Tensor
,
torch
::
Tensor
>
scatter_min
(
torch
::
Tensor
src
,
torch
::
Tensor
index
,
int64_t
dim
,
torch
::
optional
<
torch
::
Tensor
>
optional_out
,
torch
::
optional
<
int64_t
>
dim_size
);
std
::
tuple
<
torch
::
Tensor
,
torch
::
Tensor
>
scatter_max
(
torch
::
Tensor
src
,
torch
::
Tensor
index
,
int64_t
dim
,
torch
::
optional
<
torch
::
Tensor
>
optional_out
,
torch
::
optional
<
int64_t
>
dim_size
);
torch
::
Tensor
segment_sum_coo
(
torch
::
Tensor
src
,
torch
::
Tensor
index
,
torch
::
optional
<
torch
::
Tensor
>
optional_out
,
torch
::
optional
<
int64_t
>
dim_size
);
torch
::
Tensor
segment_mean_coo
(
torch
::
Tensor
src
,
torch
::
Tensor
index
,
torch
::
optional
<
torch
::
Tensor
>
optional_out
,
torch
::
optional
<
int64_t
>
dim_size
);
std
::
tuple
<
torch
::
Tensor
,
torch
::
Tensor
>
segment_min_coo
(
torch
::
Tensor
src
,
torch
::
Tensor
index
,
torch
::
optional
<
torch
::
Tensor
>
optional_out
,
torch
::
optional
<
int64_t
>
dim_size
);
std
::
tuple
<
torch
::
Tensor
,
torch
::
Tensor
>
segment_max_coo
(
torch
::
Tensor
src
,
torch
::
Tensor
index
,
torch
::
optional
<
torch
::
Tensor
>
optional_out
,
torch
::
optional
<
int64_t
>
dim_size
);
torch
::
Tensor
gather_coo
(
torch
::
Tensor
src
,
torch
::
Tensor
index
,
torch
::
optional
<
torch
::
Tensor
>
optional_out
);
torch
::
Tensor
segment_sum_csr
(
torch
::
Tensor
src
,
torch
::
Tensor
indptr
,
torch
::
optional
<
torch
::
Tensor
>
optional_out
);
torch
::
Tensor
segment_mean_csr
(
torch
::
Tensor
src
,
torch
::
Tensor
indptr
,
torch
::
optional
<
torch
::
Tensor
>
optional_out
);
std
::
tuple
<
torch
::
Tensor
,
torch
::
Tensor
>
segment_min_csr
(
torch
::
Tensor
src
,
torch
::
Tensor
indptr
,
torch
::
optional
<
torch
::
Tensor
>
optional_out
);
std
::
tuple
<
torch
::
Tensor
,
torch
::
Tensor
>
segment_max_csr
(
torch
::
Tensor
src
,
torch
::
Tensor
indptr
,
torch
::
optional
<
torch
::
Tensor
>
optional_out
);
torch
::
Tensor
gather_csr
(
torch
::
Tensor
src
,
torch
::
Tensor
indptr
,
torch
::
optional
<
torch
::
Tensor
>
optional_out
);
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment