pytorch/torch/csrc/THP.h
Edward Z. Yang 3598356420
Port THCS to ATen. (#8689)
* Port THCS to ATen.

General structure of the sparse implementation:
- SparseCUDATensor.{cpp, cu} and SparseCUDATensorMath.cu contain
  the same functions as their CPU analogues
- SparseCUDAApplyUtils.cuh contains what used to be in
  THCSTensor.cu
- SparseCUDABlas.cu contains what used to be THCSparse.cu

Unrelated improvements:
- Forward declared CUDA types in Context.h are now moved
  exclusively to CUDAHooks
- New getCurrentCUDASparseHandle in Context
- Support for printing CUSPARSE_STATUS_ZERO_PIVOT error message
  directly

Some unusual pieces:
- get_device got the LegacyBridge makeover, as it needs special
  logic on sparse tensors (defer to the inner tensors).
- I noticed that I need to turn off device_guard codegen
  for many functions in sparse, noticed because get_device
  became a native function, and resulted in an infinite recursion.  This was
  done by adding device_guard: False to the native definitions.  An alternative
  strategy might be to make the heuristic for deciding when to put in a device
  guard more clever.

Scaffolding removal:
- LegacyBridge now special-cases only on sparse versus dense;
  no more CUDA test (hooray!)
- Native bindings get CUDA/SparseCUDA dispatch entries.

CPU sparse refactoring:
- New SparseUtils.h header, with all of the utility functions that
  used to live in SparseTensor.cpp
- new_with_tensor_sparse now correctly handles both CPU and CUDA
- transpose functions in sparse/ turned out to be dead, so I killed them

Bugs I noticed while working on this:
- I used accessor<...>() on a CUDA tensor, because I thought it does
  the CUDA-CPU sync.  It does not.


Last mile changes:
- I killed all of the THS/THCS directories, build scripts, bindings everything.
  It is now no more!
- A bunch of trampolines in LegacyBridge are no more; anything
  that was "sparse only" is now done natively.
- `sparse_coo_tensor` is implemented a little funny, but we think
  it's a good idea.
- HIP is handled by explicitly ifdef'ing out all kernels; we'll add support
  for this at some later point in time.
- TH_INDEX_BASE is now unconditionally set to 0.
- Some uses of x.type() now replaced with x.options(), the new way of doing it.
- More notes about checked_cast_tensor, and eliminate Storage/Tensor fields in
  the code gen env when they are dead.

Signed-off-by: Edward Z. Yang <ezyang@fb.com>
2018-06-24 15:14:09 -04:00

49 lines
1.2 KiB
C

#ifndef THP_H
#define THP_H
#include "torch/csrc/python_headers.h"
#include <stdbool.h>
#include <TH/TH.h>
#include <TH/THTensor.hpp>
#include "THP_export.h"
// Back-compatibility macros, Thanks to http://cx-oracle.sourceforge.net/
// define PyInt_* macros for Python 3.x. NB: We must include Python.h first,
// otherwise we'll incorrectly conclude PyInt_Check isn't defined!
#ifndef PyInt_Check
#define PyInt_Check PyLong_Check
#define PyInt_FromLong PyLong_FromLong
#define PyInt_AsLong PyLong_AsLong
#define PyInt_Type PyLong_Type
#endif
// By default, don't specify library state (TH doesn't use one)
#define LIBRARY_STATE
#define LIBRARY_STATE_NOARGS
#define LIBRARY_STATE_TYPE
#define LIBRARY_STATE_TYPE_NOARGS
#define THWStorage THStorage
#define THWStorage_(NAME) THStorage_(NAME)
#define THWTensor THTensor
#define THWTensor_(NAME) THTensor_(NAME)
#include "PtrWrapper.h"
#include "Exceptions.h"
#include "Generator.h"
#include "Storage.h"
#include "Size.h"
#include "Module.h"
#include "Types.h"
#include "utils.h" // This requires defined Storage and Tensor types
#include "byte_order.h"
#ifdef _THP_CORE
#include "serialization.h"
#include "autograd/autograd.h"
#endif
#endif