Commit b1589f14 authored by rusty1s's avatar rusty1s
Browse files

added kernel boilerplate

parent 0a1d7c75
......@@ -2,5 +2,7 @@ __pycache__/
_ext/
build/
dist/
.cache/
.eggs/
*.egg-info/
.coverage
language: python
sudo: required
dist: trusty
matrix:
include:
- python: 2.7
- python: 3.5
- python: 3.6
install:
- if [[ $TRAVIS_PYTHON_VERSION == 2.7 ]]; then pip install --quiet http://download.pytorch.org/whl/cu80/torch-0.3.0.post4-cp27-cp27mu-linux_x86_64.whl; fi
- if [[ $TRAVIS_PYTHON_VERSION == 3.5 ]]; then pip install --quiet http://download.pytorch.org/whl/cu80/torch-0.3.0.post4-cp35-cp35m-linux_x86_64.whl; fi
- if [[ $TRAVIS_PYTHON_VERSION == 3.6 ]]; then pip install --quiet http://download.pytorch.org/whl/cu80/torch-0.3.0.post4-cp36-cp36m-linux_x86_64.whl; fi
- pip install pycodestyle
- pip install flake8
- pip install cffi
- pip install codecov
script:
- pycodestyle .
- flake8 .
- python setup.py install
- python setup.py test
after_success:
- codecov
notifications:
email: false
include LICENSE
include build.py
include build.sh
recursive-include torch_cluster/src *
recursive-include torch_cluster/kernel *
recursive-exclude torch_cluster/_ext *
[pypi-image]: https://badge.fury.io/py/torch-cluster.svg
[pypi-url]: https://pypi.python.org/pypi/torch-cluster
[build-image]: https://travis-ci.org/rusty1s/pytorch_cluster.svg?branch=master
[build-url]: https://travis-ci.org/rusty1s/pytorch_cluster
[coverage-image]: https://codecov.io/gh/rusty1s/pytorch_cluster/branch/master/graph/badge.svg
[coverage-url]: https://codecov.io/github/rusty1s/pytorch_cluster?branch=master
# PyTorch Cluster
[![PyPI Version][pypi-image]][pypi-url]
[![Build Status][build-image]][build-url]
[![Code Coverage][coverage-image]][coverage-url]
--------------------------------------------------------------------------------
This package consists of a small extension library of highly optimised graph cluster algorithms for the use in [PyTorch](http://pytorch.org/).
......@@ -12,7 +23,7 @@ If not, add cuda (`/usr/local/cuda/bin`) to your `$PATH`.
Then run:
```
pip install cffi
pip install cffi torch-cluster
python setup.py install
```
......
......@@ -11,7 +11,7 @@ extra_objects = []
with_cuda = False
if torch.cuda.is_available():
subprocess.call('./build.sh') # Compile kernel.
subprocess.call('./build.sh')
headers += ['torch_cluster/src/cuda.h']
sources += ['torch_cluster/src/cuda.c']
......
#!/bin/sh
echo "Compiling kernel..."
TORCH=$(python -c "import os; import torch; print(os.path.dirname(torch.__file__))")
SRC_DIR=torch_unique/kernel
BUILD_DIR=torch_unique/build
SRC_DIR=torch_cluster/kernel
BUILD_DIR=torch_cluster/build
mkdir -p $BUILD_DIR
nvcc -c -o $BUILD_DIR/kernel.so $SRC_DIR/kernel.cu -arch=sm_35 -Xcompiler -fPIC -shared -I$TORCH/lib/include/TH -I$TORCH/lib/include/THC -I$SRC_DIR
......@@ -2,8 +2,6 @@ from os import path as osp
from setuptools import setup, find_packages
import build # noqa
__version__ = '0.1.0'
url = 'https://github.com/rusty1s/pytorch_cluster'
......@@ -14,7 +12,8 @@ tests_require = ['pytest', 'pytest-cov']
setup(
name='torch_cluster',
version=__version__,
description='PyTorch Geometric Deep Learning Graph Cluster Algorithms',
description='PyTorch Extension Library of Optimised Graph Cluster '
'Algorithms',
author='Matthias Fey',
author_email='matthias.fey@tu-dortmund.de',
url=url,
......
import torch
from torch._tensor_docs import tensor_classes
tensors = [t[:-4] for t in tensor_classes]
def Tensor(str, x):
tensor = getattr(torch, str)
return tensor(x)
#ifndef THC_GENERIC_FILE
#define THC_GENERIC_FILE "generic/kernel.cu"
#else
void cluster_(grid)(THCState *state, int C, THCudaLongTensor *output, THCTensor *position, THCTensor *size, THCudaLongTensor *count) {
}
#endif
#include <THC.h>
#include "kernel.h"
#define cluster_(NAME) TH_CONCAT_4(cluster, NAME, _kernel_, Real)
#include "generic/kernel.cu"
#include "THCGenerateAllTypes.h"
#ifdef __cplusplus
extern "C" {
#endif
void cluster_grid_kernel_Float (THCState *state, int C, THCudaLongTensor *output, THCudaTensor *position, THCudaTensor *size, THCudaLongTensor *count);
void cluster_grid_kernel_Double(THCState *state, int C, THCudaLongTensor *output, THCudaDoubleTensor *position, THCudaDoubleTensor *size, THCudaLongTensor *count);
void cluster_grid_kernel_Byte (THCState *state, int C, THCudaLongTensor *output, THCudaByteTensor *position, THCudaByteTensor *size, THCudaLongTensor *count);
void cluster_grid_kernel_Char (THCState *state, int C, THCudaLongTensor *output, THCudaCharTensor *position, THCudaCharTensor *size, THCudaLongTensor *count);
void cluster_grid_kernel_Short (THCState *state, int C, THCudaLongTensor *output, THCudaShortTensor *position, THCudaShortTensor *size, THCudaLongTensor *count);
void cluster_grid_kernel_Int (THCState *state, int C, THCudaLongTensor *output, THCudaIntTensor *position, THCudaIntTensor *size, THCudaLongTensor *count);
void cluster_grid_kernel_Long (THCState *state, int C, THCudaLongTensor *output, THCudaLongTensor *position, THCudaLongTensor *size, THCudaLongTensor *count);
#ifdef __cplusplus
}
#endif
#include <THC/THC.h>
#include "kernel.h"
#define cluster_(NAME) TH_CONCAT_4(cluster_, NAME, _cuda_, Real)
#define cluster_kernel_(NAME) TH_CONCAT_4(cluster_, NAME, _kernel_, Real)
extern THCState *state;
#include "generic/cuda.c"
#include "THCGenerateFloatType.h"
#include "generic/cuda.c"
#include "THCGenerateDoubleType.h"
#include "generic/cuda.c"
#include "THCGenerateByteType.h"
#include "generic/cuda.c"
#include "THCGenerateCharType.h"
#include "generic/cuda.c"
#include "THCGenerateShortType.h"
#include "generic/cuda.c"
#include "THCGenerateIntType.h"
#include "generic/cuda.c"
#include "THCGenerateLongType.h"
void cluster_grid_cuda_Float (int C, THCudaLongTensor *output, THCudaTensor *position, THCudaTensor *size, THCudaLongTensor *count);
void cluster_grid_cuda_Double(int C, THCudaLongTensor *output, THCudaDoubleTensor *position, THCudaDoubleTensor *size, THCudaLongTensor *count);
void cluster_grid_cuda_Byte (int C, THCudaLongTensor *output, THCudaByteTensor *position, THCudaByteTensor *size, THCudaLongTensor *count);
void cluster_grid_cuda_Char (int C, THCudaLongTensor *output, THCudaCharTensor *position, THCudaCharTensor *size, THCudaLongTensor *count);
void cluster_grid_cuda_Short (int C, THCudaLongTensor *output, THCudaShortTensor *position, THCudaShortTensor *size, THCudaLongTensor *count);
void cluster_grid_cuda_Int (int C, THCudaLongTensor *output, THCudaIntTensor *position, THCudaIntTensor *size, THCudaLongTensor *count);
void cluster_grid_cuda_Long (int C, THCudaLongTensor *output, THCudaLongTensor *position, THCudaLongTensor *size, THCudaLongTensor *count);
#ifndef THC_GENERIC_FILE
#define THC_GENERIC_FILE "generic/cuda.c"
#else
void cluster_(grid)(int C, THCudaLongTensor *output, THCTensor *position, THCTensor *size, THCudaLongTensor *count) {
return cluster_kernel_(grid)(state, C, output, position, size, count);
}
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment