Skip to content

Initial f16 support - #2413

Merged
umar456 merged 7 commits into
arrayfire:masterfrom
umar456:half
Jun 28, 2019
Merged

umar456 merged 7 commits into
arrayfire:masterfrom
umar456:half

Conversation

@umar456

@umar456 umar456 commented Jan 18, 2019 •

Copy link
Copy Markdown
Member

Initial support for fp16:

  • JIT
  • Random Number Generation
  • matmul
  • reductions
  • reorder/transpose
  • printing
  • casts
  • tests
  • [ ] convolution
  • [ ] anything else

@umar456 umar456 changed the title Implement f16 support Initial f16 support Jan 18, 2019
@WilliamTambellini

Copy link
Copy Markdown
Contributor

why is there
"
Initial support for fp16:
CPU
"
in the description ?

@umar456

umar456 commented Jan 19, 2019

Copy link
Copy Markdown
Member Author

I was thinking of making a table but thought against it. Fixed the message.

Comment thread CMakeModules/InternalUtils.cmake Resolved
Comment thread src/backend/common/half.hpp Resolved
Comment thread src/backend/cuda/blas.cpp Resolved
Comment thread src/backend/cuda/CMakeLists.txt Resolved

@9prady9 9prady9 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, I guess you are still adding more tests - for all the functions for which half support has been enabled.

Comment thread include/af/half.h Resolved
Comment thread src/api/c/blas.cpp Resolved
Comment thread src/api/cpp/seq.cpp Resolved
Comment thread src/backend/cuda/kernel/memcopy.hpp Resolved
Comment thread src/backend/opencl/err_opencl.hpp Resolved
Comment thread include/af/half.h Resolved
@9prady9 9prady9 mentioned this pull request Mar 13, 2019
@umar456
umar456 force-pushed the half branch 2 times, most recently from 3ac84cb to 10424f0 Compare March 14, 2019 14:15
@umar456 umar456 added this to the v3.7.0 milestone May 31, 2019
@umar456
umar456 force-pushed the half branch 2 times, most recently from b79c549 to e6dbac0 Compare June 24, 2019 02:18
Comment thread CMakeModules/InternalUtils.cmake Resolved
Comment thread include/af/device.h
/// \returns true if the \p device supports half precision operations.
/// false otherwise
/// \ingroup device_func_half
AFAPI bool isHalfAvailable(const int device);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add more comments in order to give some examples of which device will return true which false ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if that would help users in a general way. Perhaps, a new page in our documentation that lists known devices with half support or hyperlink to a page which has this information is better.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On my side I m more interested to know if the device can handle half natively with better perf than f32 (most of the time meaning Volta/Turing via TensorCores and apparently P100).
Is nt that method going to return true on old GPUs (GTX10X0) where half is perhaps "supported" but perf is disastrous ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The half support for the 10x0 cards are supported through floats.

Even on the Volta cards we need to improve the way we handle things to improve the compute performance. In order to fully utilize the GPU's half compute performance we need to use half2. This will require a major shift on some of the internal kernels so I pushed that change off to later. We can talk about what functions are important to you and improve those later down the line. All the library calls for half(i.e. matmul) will be using half2 so you will get full compute performance there. If there are kernels that are bandwidth bound moving to half2 will serve no purpose because it will still be a bandwidth bound kernel.

Comment thread src/backend/cuda/platform.cpp Resolved
Comment thread src/backend/cuda/blas.cpp Resolved
Comment thread src/backend/cuda/CMakeLists.txt Resolved
Comment thread include/af/device.h
/// \returns true if the \p device supports half precision operations.
/// false otherwise
/// \ingroup device_func_half
AFAPI bool isHalfAvailable(const int device);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if that would help users in a general way. Perhaps, a new page in our documentation that lists known devices with half support or hyperlink to a page which has this information is better.

Comment thread src/api/c/array.cpp Resolved
Comment thread src/api/c/binary.cpp Resolved
Comment thread src/api/c/blas.cpp Resolved
Comment thread src/api/c/data.cpp Resolved
Comment thread src/backend/opencl/kernel/transpose.cl Resolved
Comment thread test/array.cpp Resolved
Comment thread test/join.cpp
// create a list of types to be tested
typedef ::testing::Types<float, double, cfloat, cdouble, int, unsigned int,
intl, uintl, char, unsigned char, short, ushort>
intl, uintl, char, unsigned char, short, ushort, af_half>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should be C++ typedef af::half to be consistent with cfloat and cboudle. This applies to all the tests where half is enabled.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am worried we will have conflicts with the half data type. I want to discourage the use of this type by users because of its inefficiency. I am not sure if this is the best way to handle this sort of thing.

Comment thread test/testHelpers.hpp

const af::cdouble &operator+(const af::cdouble &val) { return val; }

const af_half& operator+(const af_half& val) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

af::half to be consistent with other af::* types.

Comment thread test/testHelpers.hpp
return lhs.data_ == rhs.data_;
}

std::ostream &operator<<(std::ostream &os, const af_half &val) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we use half_float::half from extern/half/include/half.hpp only in tests ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Our half type is not fully functional. It would require us to reimplement the entire half library inorder to correctly implement it. I don't think we should directly include other libraries in our API. perhaps we can discuss it in a separate issue.

umar456 added 4 commits June 27, 2019 12:54
* Add half support for gemm
* Add half support for JIT
* Set the c++ standard to c++14 internally
* Add support functions for half support.
* Add half support to reductions.
* Add support for join

@syurkevi syurkevi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you open an issue to fix half testing?
Everything else looking good! Like the random cleanups. 👍

Comment thread test/reduce.cpp
ASSERT_ARRAYS_EQ(gold, out);
}

// TODO(umar): HalfMax

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO?

Comment thread test/array.cpp
EXPECT_TRUE(one.isreal());
EXPECT_FALSE(one.iscomplex());
EXPECT_FALSE(one.isbool());
EXPECT_FALSE(one.ishalf());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EXPECT_TRUE?

@umar456
umar456 merged commit a23c00b into arrayfire:master Jun 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants