-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add translated AttentionKernel. Need to do validate on the files.
Showing
11 changed files
with
3,617 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#include "AttentionDescriptor.hpp" | ||
#include "AttentionKernelDescriptor.hpp" | ||
// #include "AttentionKernel.hpp" | ||
#include "../ccv_nnc_mfa_hash.hpp" | ||
#include "../ccv_nnc_mfa_error.hpp" | ||
|
||
bool AttentionDescriptor::operator==(const AttentionDescriptor& rhs) const { | ||
return | ||
(lowPrecisionInputs == rhs.lowPrecisionInputs) && | ||
(lowPrecisionIntermediates == rhs.lowPrecisionIntermediates) && | ||
simd_all(matrixDimensions == rhs.matrixDimensions) && | ||
simd_all(transposeState == rhs.transposeState); | ||
} | ||
|
||
std::size_t std::hash<AttentionDescriptor>::operator()(const AttentionDescriptor& hash) const noexcept { | ||
std::size_t seed = 0; | ||
using namespace ccv::nnc::mfa::hash; | ||
combine_32(seed, hash.matrixDimensions[0]); | ||
combine_32(seed, hash.matrixDimensions[1]); | ||
combine_32(seed, hash.matrixDimensions[2]); | ||
combine_32(seed, pack_32(simd::uchar4 { hash.transposeState[0], hash.transposeState[1], hash.transposeState[2], hash.transposeState[3] })); | ||
combine_32(seed, pack_32(simd::uchar4 { hash.lowPrecisionInputs, hash.lowPrecisionIntermediates, 0, 0 })); | ||
return seed; | ||
} | ||
|
||
/* | ||
std::pair<AttentionKernelDescriptor, PipelineValue<AttentionKernel> *> AttentionDescriptor::findKernel(MTL::Device *const device, const DeviceProperties &dprops, std::unordered_map<AttentionKernelDescriptor, std::unique_ptr<AttentionKernel>> *const libraryCache) const noexcept { | ||
} | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#ifndef MFA_ATTENTIONDESCRIPTOR_HPP_ | ||
#define MFA_ATTENTIONDESCRIPTOR_HPP_ | ||
|
||
#include <simd/simd.h> | ||
#include <utility> | ||
#include "PipelineValue.hpp" | ||
#include "DeviceProperties.hpp" | ||
#include "GEMMOperandPrecision.hpp" | ||
|
||
struct AttentionKernelDescriptor; | ||
struct AttentionKernel; | ||
|
||
struct AttentionDescriptor { | ||
/// Q, K, V, dO | ||
bool lowPrecisionInputs; | ||
|
||
/// S, P, L, D, dP, dS | ||
bool lowPrecisionIntermediates; | ||
|
||
/// row: Output sequence length; rows of the attention matrix. | ||
/// column: Input sequence length; columns of the attention matrix. | ||
/// head: Head dimension, typically 32 - 256. | ||
simd::uint3 matrixDimensions; | ||
|
||
/// Q, K, V, O | ||
simd::uchar4 transposeState; | ||
|
||
bool operator==(const AttentionDescriptor& rhs) const; | ||
|
||
// std::pair<AttentionKernelDescriptor, PipelineValue<AttentionKernel> *> findKernel(MTL::Device* const device, const DeviceProperties &dprops, std::unordered_map<AttentionKernelDescriptor, std::unique_ptr<AttentionKernel>> *const libraryCache) const noexcept; | ||
}; | ||
|
||
template<> | ||
struct std::hash<AttentionDescriptor> | ||
{ | ||
std::size_t operator()(const AttentionDescriptor& hash) const noexcept; | ||
}; | ||
|
||
#endif | ||
|
Oops, something went wrong.