Add support for torch.HalfTensor #874

Merged
merged 3 commits into from Dec 29, 2016

Projects

None yet

3 participants

@gchanan
Contributor
gchanan commented Dec 21, 2016

NOTE: this should not be merged until the cutorch equivalent is ready; I'm working on that based on torch/cutorch#578. This pull request won't break anything but because cutorch's generics overwrite the torch generics, you can lose some HalfTensor functionality via "require cutorch"

This is based on #826/ (which is the first commit in this request), with the following improvements/simplifications (the second commit):

Improvements/Simplifications:

  1. No longer generates math functions that are not actually defined
    on torch.HalfTensor, e.g. maskedFill, map2, etc.
  2. Adds tests for all available torch.HalfTensor functions.
  3. Allows compiling without TH_GENERIC_USE_HALF (so if there's a
    problem can just unset that in CMakeLists rather than backing out)
  4. Some simplifications: removes a new copy optimization and
    some TH_HALF literal definitions; I'd rather not include optimizations
    to non-half types in this PR.

Limitations:
Because match functions are not defined, some "non-math" operators
on torch.HalfTensor give an error message, e.g. index/newindex
with a ByteTensor apply a mask, but masks aren't implemented. These
limitations aren't always obvious (e.g. for documentation purposes), but
they should always give an error message.

soumith and others added some commits Dec 20, 2016
@soumith soumith Add support for torch.HalfTensor. 1a99547
Gregory Chanan Improvements/Simplifications for torch.HalfTensor.
Improvements/Simplifications:
1) Defines half type as TH_Half, so as to not conflict with cutorch
version.  Previously, these were defined as the same "half" type and
required proper ordering of includes to ensure type was only defined
once, which would have affected all downstream projects.
2) No longer generates math functions that are not actually defined
on torch.HalfTensor, e.g. maskedFill, map, etc.
3) Adds tests for all available torch.HalfTensor functions
4) Allows compiling without TH_GENERIC_USE_HALF (so if there's a
problem can just unset that in CMakeLists rather than backing out)
5) Some simplifications: removes a new copy optimization and
some TH_HALF literal definitions

Limitations:
Because match functions are not defined, some "non-math" operators
on torch.HalfTensor give an error message, e.g. __index__/__newindex__
with a ByteTensor apply a mask, but masks aren't implemented.  These
limitations aren't always obvious, (e.g. for documentation purposes),
but they should always give an error message.
37814a6
@gchanan
Contributor
gchanan commented Dec 27, 2016

This should be ready to merge once the cutorch changes are ready. We now define a different TH_HALF type instead of defining 'half' as in cutorch; defining 'half' requires that files are included in the proper order so that cutorch does not redefine 'half'; this is probably doable, but tricky for downstream projects to get right.

@gchanan gchanan referenced this pull request in torch/cutorch Dec 28, 2016
Merged

Add THHalfTensor support to cutorch #655

@gchanan
Contributor
gchanan commented Dec 28, 2016

equivalent cutorch PR here: torch/cutorch#655

@soumith soumith merged commit a0c0b78 into torch:master Dec 29, 2016

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
@borisfom borisfom referenced this pull request in torch/cutorch Dec 30, 2016
Closed

Using Torch.HalfTensor #578

@borisfom
Contributor

Thanks for completing this! Yes using separate type for Half makes better sense (I started with that option, too). It should make it simpler to adopt a tricky __fp16 gcc ARM type, too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment