2017-01-17 14:57:51 -06:00
|
|
|
/*
|
2023-04-26 18:13:36 +00:00
|
|
|
Copyright (c) 2015 - 2023 Advanced Micro Devices, Inc. All rights reserved.
|
2017-03-31 12:18:55 -05:00
|
|
|
|
2017-01-17 14:57:51 -06:00
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
|
furnished to do so, subject to the following conditions:
|
2017-03-31 12:18:55 -05:00
|
|
|
|
2017-01-17 14:57:51 -06:00
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
|
all copies or substantial portions of the Software.
|
2017-03-31 12:18:55 -05:00
|
|
|
|
2017-01-17 14:57:51 -06:00
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
|
THE SOFTWARE.
|
|
|
|
|
*/
|
|
|
|
|
|
2018-05-31 03:17:26 +01:00
|
|
|
#pragma once
|
2017-10-02 21:52:16 +00:00
|
|
|
|
2023-04-26 18:13:36 +00:00
|
|
|
#if !defined(__HIPCC_RTC__)
|
2018-10-10 11:43:49 +01:00
|
|
|
#include "hip_fp16_math_fwd.h"
|
2021-05-28 23:15:18 +00:00
|
|
|
#include "amd_hip_vector_types.h"
|
2018-06-01 22:55:33 +01:00
|
|
|
#include "math_fwd.h"
|
2017-10-02 21:52:16 +00:00
|
|
|
|
2020-12-15 17:38:08 -05:00
|
|
|
#include <hip/amd_detail/host_defines.h>
|
2018-05-31 03:17:26 +01:00
|
|
|
|
2018-09-17 11:50:29 +03:00
|
|
|
#include <algorithm>
|
2019-08-15 22:13:33 -04:00
|
|
|
// assert.h is only for the host version of assert.
|
2020-12-15 17:38:08 -05:00
|
|
|
// The device version of assert is implemented in hip/amd_detail/hip_runtime.h.
|
2019-08-15 22:13:33 -04:00
|
|
|
// Users should include hip_runtime.h for the device version of assert.
|
|
|
|
|
#if !__HIP_DEVICE_COMPILE__
|
2018-05-31 03:17:26 +01:00
|
|
|
#include <assert.h>
|
2019-08-15 22:13:33 -04:00
|
|
|
#endif
|
2018-05-31 16:38:00 +01:00
|
|
|
#include <limits.h>
|
2018-06-28 22:33:46 -04:00
|
|
|
#include <limits>
|
2018-05-31 03:17:26 +01:00
|
|
|
#include <stdint.h>
|
2021-05-05 21:26:21 +00:00
|
|
|
#endif // !defined(__HIPCC_RTC__)
|
2018-05-31 03:17:26 +01:00
|
|
|
|
2018-06-28 22:33:46 -04:00
|
|
|
#pragma push_macro("__DEVICE__")
|
|
|
|
|
#pragma push_macro("__RETURN_TYPE")
|
|
|
|
|
|
|
|
|
|
#define __DEVICE__ static __device__
|
|
|
|
|
#define __RETURN_TYPE bool
|
|
|
|
|
|
2019-01-11 23:22:07 +00:00
|
|
|
// DOT FUNCTIONS
|
2023-11-29 09:19:48 +00:00
|
|
|
#if defined(__clang__) && defined(__HIP__)
|
2019-01-11 23:22:07 +00:00
|
|
|
__DEVICE__
|
|
|
|
|
inline
|
|
|
|
|
int amd_mixed_dot(short2 a, short2 b, int c, bool saturate) {
|
2019-01-22 22:31:19 +00:00
|
|
|
return __ockl_sdot2(a.data, b.data, c, saturate);
|
2019-01-11 23:22:07 +00:00
|
|
|
}
|
|
|
|
|
__DEVICE__
|
|
|
|
|
inline
|
|
|
|
|
uint amd_mixed_dot(ushort2 a, ushort2 b, uint c, bool saturate) {
|
2019-01-22 22:31:19 +00:00
|
|
|
return __ockl_udot2(a.data, b.data, c, saturate);
|
2019-01-11 23:22:07 +00:00
|
|
|
}
|
|
|
|
|
__DEVICE__
|
|
|
|
|
inline
|
|
|
|
|
int amd_mixed_dot(char4 a, char4 b, int c, bool saturate) {
|
2019-01-22 22:31:19 +00:00
|
|
|
return __ockl_sdot4(a.data, b.data, c, saturate);
|
2019-01-11 23:22:07 +00:00
|
|
|
}
|
|
|
|
|
__DEVICE__
|
|
|
|
|
inline
|
|
|
|
|
uint amd_mixed_dot(uchar4 a, uchar4 b, uint c, bool saturate) {
|
2019-01-22 22:31:19 +00:00
|
|
|
return __ockl_udot4(a.data, b.data, c, saturate);
|
2019-01-11 23:22:07 +00:00
|
|
|
}
|
|
|
|
|
__DEVICE__
|
|
|
|
|
inline
|
|
|
|
|
int amd_mixed_dot(int a, int b, int c, bool saturate) {
|
|
|
|
|
return __ockl_sdot8(a, b, c, saturate);
|
|
|
|
|
}
|
|
|
|
|
__DEVICE__
|
|
|
|
|
inline
|
|
|
|
|
uint amd_mixed_dot(uint a, uint b, uint c, bool saturate) {
|
|
|
|
|
return __ockl_udot8(a, b, c, saturate);
|
|
|
|
|
}
|
2019-01-14 23:14:49 +00:00
|
|
|
#endif
|
2019-01-11 23:22:07 +00:00
|
|
|
|
2023-04-26 18:13:36 +00:00
|
|
|
#pragma pop_macro("__DEVICE__")
|
|
|
|
|
#pragma pop_macro("__RETURN_TYPE")
|
|
|
|
|
// For backward compatibility.
|
|
|
|
|
// There are HIP applications e.g. TensorFlow, expecting __HIP_ARCH_* macros
|
|
|
|
|
// defined after including math_functions.h.
|
|
|
|
|
#if !defined(__HIPCC_RTC__)
|
|
|
|
|
#include <hip/amd_detail/amd_hip_runtime.h>
|
|
|
|
|
#endif
|