Cleaning. Removed TensorCodeGenerator.
PiperOrigin-RevId: 318882704 Change-Id: I5386e7bc38cf7e1059edb24e1078b7a2cdd6fc9f
This commit is contained in:
parent
0a36436b9f
commit
92d15f9719
@ -122,436 +122,6 @@ std::string GetCommonDefines(CalculationsPrecision precision) {
|
||||
return result;
|
||||
}
|
||||
|
||||
TensorCodeGenerator::TensorCodeGenerator(const std::string& name,
|
||||
const WHSPoint& sizes,
|
||||
const TensorDescriptor& descriptor)
|
||||
: tensor_name_(name),
|
||||
width_name_(sizes.w_name),
|
||||
height_name_(sizes.h_name),
|
||||
slices_name_(sizes.s_name),
|
||||
descriptor_(descriptor) {}
|
||||
|
||||
TensorCodeGenerator::TensorCodeGenerator(const std::string& name,
|
||||
const WHSBPoint& sizes,
|
||||
const TensorDescriptor& descriptor)
|
||||
: tensor_name_(name),
|
||||
width_name_(sizes.w_name),
|
||||
height_name_(sizes.h_name),
|
||||
slices_name_(sizes.s_name),
|
||||
batch_name_(sizes.b_name),
|
||||
descriptor_(descriptor) {}
|
||||
|
||||
TensorCodeGenerator::TensorCodeGenerator(const std::string& name,
|
||||
const WHDSPoint& sizes,
|
||||
const TensorDescriptor& descriptor)
|
||||
: tensor_name_(name),
|
||||
width_name_(sizes.w_name),
|
||||
height_name_(sizes.h_name),
|
||||
depth_name_(sizes.d_name),
|
||||
slices_name_(sizes.s_name),
|
||||
descriptor_(descriptor) {}
|
||||
|
||||
TensorCodeGenerator::TensorCodeGenerator(const std::string& name,
|
||||
const WHDSBPoint& sizes,
|
||||
const TensorDescriptor& descriptor)
|
||||
: tensor_name_(name),
|
||||
width_name_(sizes.w_name),
|
||||
height_name_(sizes.h_name),
|
||||
depth_name_(sizes.d_name),
|
||||
slices_name_(sizes.s_name),
|
||||
batch_name_(sizes.b_name),
|
||||
descriptor_(descriptor) {}
|
||||
|
||||
std::string TensorCodeGenerator::GetDeclaration(AccessType access_type) const {
|
||||
return GetTensorDeclaration(access_type, tensor_name_, descriptor_);
|
||||
}
|
||||
|
||||
std::string TensorCodeGenerator::ReadWHS(
|
||||
const std::string& x, const std::string& y, const std::string& s,
|
||||
TextureAddressMode address_mode) const {
|
||||
return Read(GetGlobalAddressNoDeclarationWHS(x, y, s), address_mode);
|
||||
}
|
||||
|
||||
std::string TensorCodeGenerator::ReadWHSB(
|
||||
const std::string& x, const std::string& y, const std::string& s,
|
||||
const std::string& b, TextureAddressMode address_mode) const {
|
||||
return Read(GetGlobalAddressNoDeclarationWHSB(x, y, s, b), address_mode);
|
||||
}
|
||||
|
||||
std::string TensorCodeGenerator::ReadWHDS(
|
||||
const std::string& x, const std::string& y, const std::string& z,
|
||||
const std::string& s, TextureAddressMode address_mode) const {
|
||||
return Read(GetGlobalAddressNoDeclarationWHDS(x, y, z, s), address_mode);
|
||||
}
|
||||
|
||||
std::string TensorCodeGenerator::ReadWHDSB(
|
||||
const std::string& x, const std::string& y, const std::string& z,
|
||||
const std::string& s, const std::string& b,
|
||||
TextureAddressMode address_mode) const {
|
||||
return Read(GetGlobalAddressNoDeclarationWHDSB(x, y, z, s, b), address_mode);
|
||||
}
|
||||
|
||||
std::string TensorCodeGenerator::ReadAsFloatWHS(
|
||||
const std::string& x, const std::string& y, const std::string& s,
|
||||
TextureAddressMode address_mode) const {
|
||||
return ReadAsFloat(GetGlobalAddressNoDeclarationWHS(x, y, s), address_mode);
|
||||
}
|
||||
|
||||
std::string TensorCodeGenerator::ReadAsFloatWHSB(
|
||||
const std::string& x, const std::string& y, const std::string& s,
|
||||
const std::string& b, TextureAddressMode address_mode) const {
|
||||
return ReadAsFloat(GetGlobalAddressNoDeclarationWHSB(x, y, s, b),
|
||||
address_mode);
|
||||
}
|
||||
|
||||
std::string TensorCodeGenerator::ReadAsFloatWHDS(
|
||||
const std::string& x, const std::string& y, const std::string& z,
|
||||
const std::string& s, TextureAddressMode address_mode) const {
|
||||
return ReadAsFloat(GetGlobalAddressNoDeclarationWHDS(x, y, z, s),
|
||||
address_mode);
|
||||
}
|
||||
|
||||
std::string TensorCodeGenerator::ReadAsFloatWHDSB(
|
||||
const std::string& x, const std::string& y, const std::string& z,
|
||||
const std::string& s, const std::string& b,
|
||||
TextureAddressMode address_mode) const {
|
||||
return ReadAsFloat(GetGlobalAddressNoDeclarationWHDSB(x, y, z, s, b),
|
||||
address_mode);
|
||||
}
|
||||
|
||||
std::string TensorCodeGenerator::ReadAsTypeWHS(
|
||||
DataType type, const std::string& x, const std::string& y,
|
||||
const std::string& s, TextureAddressMode address_mode) const {
|
||||
return ReadAsType(type, GetGlobalAddressNoDeclarationWHS(x, y, s),
|
||||
address_mode);
|
||||
}
|
||||
|
||||
std::string TensorCodeGenerator::ReadAsTypeWHSB(
|
||||
DataType type, const std::string& x, const std::string& y,
|
||||
const std::string& s, const std::string& b,
|
||||
TextureAddressMode address_mode) const {
|
||||
return ReadAsType(type, GetGlobalAddressNoDeclarationWHSB(x, y, s, b),
|
||||
address_mode);
|
||||
}
|
||||
|
||||
std::string TensorCodeGenerator::ReadAsTypeWHDS(
|
||||
DataType type, const std::string& x, const std::string& y,
|
||||
const std::string& z, const std::string& s,
|
||||
TextureAddressMode address_mode) const {
|
||||
return ReadAsType(type, GetGlobalAddressNoDeclarationWHDS(x, y, z, s),
|
||||
address_mode);
|
||||
}
|
||||
|
||||
std::string TensorCodeGenerator::ReadAsTypeWHDSB(
|
||||
DataType type, const std::string& x, const std::string& y,
|
||||
const std::string& z, const std::string& s, const std::string& b,
|
||||
TextureAddressMode address_mode) const {
|
||||
return ReadAsType(type, GetGlobalAddressNoDeclarationWHDSB(x, y, z, s, b),
|
||||
address_mode);
|
||||
}
|
||||
|
||||
std::string TensorCodeGenerator::GetAddressWHS(const std::string& var_name,
|
||||
const std::string& x,
|
||||
const std::string& y,
|
||||
const std::string& s) const {
|
||||
return DeclareAddress(var_name, GetGlobalAddressNoDeclarationWHS(x, y, s));
|
||||
}
|
||||
|
||||
std::string TensorCodeGenerator::GetAddressWHSB(const std::string& var_name,
|
||||
const std::string& x,
|
||||
const std::string& y,
|
||||
const std::string& s,
|
||||
const std::string& b) const {
|
||||
return DeclareAddress(var_name,
|
||||
GetGlobalAddressNoDeclarationWHSB(x, y, s, b));
|
||||
}
|
||||
|
||||
std::string TensorCodeGenerator::GetAddressWHDS(const std::string& var_name,
|
||||
const std::string& x,
|
||||
const std::string& y,
|
||||
const std::string& z,
|
||||
const std::string& s) const {
|
||||
return DeclareAddress(var_name,
|
||||
GetGlobalAddressNoDeclarationWHDS(x, y, z, s));
|
||||
}
|
||||
|
||||
std::string TensorCodeGenerator::GetAddressWHDSB(
|
||||
const std::string& var_name, const std::string& x, const std::string& y,
|
||||
const std::string& z, const std::string& s, const std::string& b) const {
|
||||
return DeclareAddress(var_name,
|
||||
GetGlobalAddressNoDeclarationWHDSB(x, y, z, s, b));
|
||||
}
|
||||
|
||||
std::string TensorCodeGenerator::GetGlobalAddressNoDeclarationWHS(
|
||||
const std::string& x, const std::string& y, const std::string& s) const {
|
||||
switch (descriptor_.storage_type) {
|
||||
case TensorStorageType::BUFFER:
|
||||
case TensorStorageType::IMAGE_BUFFER:
|
||||
return absl::Substitute("((($2) * $3 + ($1)) * $4 + ($0))", x, y, s,
|
||||
height_name_, width_name_);
|
||||
case TensorStorageType::TEXTURE_2D:
|
||||
return absl::Substitute("(int2)(($0), ($1) * $3 + ($2))", x, y, s,
|
||||
slices_name_);
|
||||
case TensorStorageType::SINGLE_TEXTURE_2D:
|
||||
return absl::StrCat("(int2)(", x, ", ", y, ")");
|
||||
case TensorStorageType::TEXTURE_ARRAY:
|
||||
case TensorStorageType::TEXTURE_3D:
|
||||
return absl::StrCat("(int4)(", x, ", ", y, ", ", s, ", 0)");
|
||||
case TensorStorageType::UNKNOWN:
|
||||
return "error";
|
||||
}
|
||||
}
|
||||
|
||||
std::string TensorCodeGenerator::GetGlobalAddressNoDeclarationWHSB(
|
||||
const std::string& x, const std::string& y, const std::string& s,
|
||||
const std::string& b) const {
|
||||
if (b.empty()) {
|
||||
return GetGlobalAddressNoDeclarationWHS(x, y, s);
|
||||
}
|
||||
switch (descriptor_.storage_type) {
|
||||
case TensorStorageType::BUFFER:
|
||||
case TensorStorageType::IMAGE_BUFFER:
|
||||
return absl::Substitute("(((($3) * $4 + $2) * $5 + ($1)) * $6 + ($0))", b,
|
||||
x, y, s, height_name_, width_name_, batch_name_);
|
||||
case TensorStorageType::TEXTURE_2D:
|
||||
return absl::Substitute("(int2)(($0) * $4 + ($1), ($2) * $5 + ($3))", x,
|
||||
b, y, s, batch_name_, slices_name_);
|
||||
case TensorStorageType::SINGLE_TEXTURE_2D:
|
||||
return absl::Substitute("(int2)(($0) * $3 + ($1), ($2))", x, b, y,
|
||||
batch_name_);
|
||||
case TensorStorageType::TEXTURE_ARRAY:
|
||||
case TensorStorageType::TEXTURE_3D:
|
||||
return absl::Substitute("(int4)(($0) * $4 + ($1), ($2), ($3), 0)", x, b,
|
||||
y, s, batch_name_);
|
||||
case TensorStorageType::UNKNOWN:
|
||||
return "error";
|
||||
default:
|
||||
return "error";
|
||||
}
|
||||
}
|
||||
|
||||
std::string TensorCodeGenerator::GetGlobalAddressNoDeclarationWHDS(
|
||||
const std::string& x, const std::string& y, const std::string& z,
|
||||
const std::string& s) const {
|
||||
switch (descriptor_.storage_type) {
|
||||
case TensorStorageType::BUFFER:
|
||||
case TensorStorageType::IMAGE_BUFFER:
|
||||
return absl::Substitute("(((($3) * $4 + ($2)) * $5 + ($1)) * $6 + ($0))",
|
||||
x, y, s, z, slices_name_, height_name_,
|
||||
width_name_);
|
||||
case TensorStorageType::TEXTURE_2D:
|
||||
return absl::Substitute("(int2)(($0) * $4 + ($1), ($2) * $5 + ($3))", x,
|
||||
z, y, s, depth_name_, slices_name_);
|
||||
case TensorStorageType::SINGLE_TEXTURE_2D:
|
||||
return absl::Substitute("(int2)(($0) * $3 + ($1), ($2))", x, z, y,
|
||||
depth_name_);
|
||||
case TensorStorageType::TEXTURE_ARRAY:
|
||||
case TensorStorageType::TEXTURE_3D:
|
||||
return absl::Substitute("(int4)(($0), ($1), ($2) * $4 + ($3), 0)", x, y,
|
||||
z, s, slices_name_);
|
||||
case TensorStorageType::UNKNOWN:
|
||||
return "error";
|
||||
}
|
||||
}
|
||||
|
||||
std::string TensorCodeGenerator::GetGlobalAddressNoDeclarationWHDSB(
|
||||
const std::string& x, const std::string& y, const std::string& z,
|
||||
const std::string& s, const std::string& b) const {
|
||||
if (b.empty()) {
|
||||
return GetGlobalAddressNoDeclarationWHDS(x, y, z, s);
|
||||
}
|
||||
switch (descriptor_.storage_type) {
|
||||
case TensorStorageType::BUFFER:
|
||||
case TensorStorageType::IMAGE_BUFFER:
|
||||
return absl::Substitute(
|
||||
"((((($4) * $5 + ($3)) * $6 + $2) * $7 + ($1)) * $8 + ($0))", b, x, y,
|
||||
s, z, slices_name_, height_name_, width_name_, batch_name_);
|
||||
case TensorStorageType::TEXTURE_2D:
|
||||
return absl::Substitute(
|
||||
"(int2)((($0) * $5 + ($1)) * $6 + ($2), ($3) * $7 + ($4))", x, b, z,
|
||||
y, s, batch_name_, depth_name_, slices_name_);
|
||||
case TensorStorageType::SINGLE_TEXTURE_2D:
|
||||
return absl::Substitute("(int2)((($0) * $4 + ($1)) * $5 + ($2), ($3))", x,
|
||||
b, z, y, batch_name_, depth_name_);
|
||||
case TensorStorageType::TEXTURE_ARRAY:
|
||||
case TensorStorageType::TEXTURE_3D:
|
||||
return absl::Substitute(
|
||||
"(int4)(($0) * $5 + ($1), ($2), ($3) * $6 + ($4), 0)", x, b, y, z, s,
|
||||
batch_name_, slices_name_);
|
||||
case TensorStorageType::UNKNOWN:
|
||||
return "error";
|
||||
default:
|
||||
return "error";
|
||||
}
|
||||
}
|
||||
|
||||
std::string TensorCodeGenerator::DeclareAddress(
|
||||
const std::string& var_name, const std::string& address) const {
|
||||
switch (descriptor_.storage_type) {
|
||||
case TensorStorageType::BUFFER:
|
||||
case TensorStorageType::IMAGE_BUFFER:
|
||||
return absl::StrCat("int ", var_name, " = ", address, ";\n");
|
||||
case TensorStorageType::TEXTURE_2D:
|
||||
case TensorStorageType::SINGLE_TEXTURE_2D:
|
||||
return absl::StrCat("int2 ", var_name, " = ", address, ";\n");
|
||||
case TensorStorageType::TEXTURE_ARRAY:
|
||||
case TensorStorageType::TEXTURE_3D:
|
||||
return absl::StrCat("int4 ", var_name, " = ", address, ";\n");
|
||||
case TensorStorageType::UNKNOWN:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
std::string TensorCodeGenerator::WriteWHS(const std::string& var_name,
|
||||
const std::string& x,
|
||||
const std::string& y,
|
||||
const std::string& s) const {
|
||||
return Write(var_name, GetGlobalAddressNoDeclarationWHS(x, y, s));
|
||||
}
|
||||
|
||||
std::string TensorCodeGenerator::WriteWHSB(const std::string& var_name,
|
||||
const std::string& x,
|
||||
const std::string& y,
|
||||
const std::string& s,
|
||||
const std::string& b) const {
|
||||
return Write(var_name, GetGlobalAddressNoDeclarationWHSB(x, y, s, b));
|
||||
}
|
||||
|
||||
std::string TensorCodeGenerator::WriteWHDS(const std::string& var_name,
|
||||
const std::string& x,
|
||||
const std::string& y,
|
||||
const std::string& z,
|
||||
const std::string& s) const {
|
||||
return Write(var_name, GetGlobalAddressNoDeclarationWHDS(x, y, z, s));
|
||||
}
|
||||
|
||||
std::string TensorCodeGenerator::WriteWHDSB(
|
||||
const std::string& var_name, const std::string& x, const std::string& y,
|
||||
const std::string& z, const std::string& s, const std::string& b) const {
|
||||
return Write(var_name, GetGlobalAddressNoDeclarationWHDSB(x, y, z, s, b));
|
||||
}
|
||||
|
||||
std::string TensorCodeGenerator::Read(const std::string& global_address,
|
||||
TextureAddressMode address_mode) const {
|
||||
switch (descriptor_.storage_type) {
|
||||
case TensorStorageType::BUFFER:
|
||||
return absl::StrCat(tensor_name_, "[", global_address, "]");
|
||||
case TensorStorageType::TEXTURE_2D:
|
||||
case TensorStorageType::TEXTURE_3D:
|
||||
case TensorStorageType::SINGLE_TEXTURE_2D:
|
||||
case TensorStorageType::TEXTURE_ARRAY:
|
||||
return absl::StrCat(
|
||||
GetReadImageFromDataType(descriptor_.data_type), "(", tensor_name_,
|
||||
", " + TextureAddressModeToString(address_mode) + ", ",
|
||||
global_address, ")");
|
||||
case TensorStorageType::IMAGE_BUFFER:
|
||||
return absl::StrCat(GetReadImageFromDataType(descriptor_.data_type), "(",
|
||||
tensor_name_, ", ", global_address, ")");
|
||||
case TensorStorageType::UNKNOWN:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
std::string TensorCodeGenerator::ReadAsFloat(
|
||||
const std::string& global_address, TextureAddressMode address_mode) const {
|
||||
switch (descriptor_.storage_type) {
|
||||
case TensorStorageType::BUFFER:
|
||||
return absl::StrCat("convert_float4(", tensor_name_, "[", global_address,
|
||||
"])");
|
||||
case TensorStorageType::TEXTURE_2D:
|
||||
case TensorStorageType::TEXTURE_3D:
|
||||
case TensorStorageType::SINGLE_TEXTURE_2D:
|
||||
case TensorStorageType::TEXTURE_ARRAY:
|
||||
return absl::StrCat(
|
||||
"read_imagef(", tensor_name_,
|
||||
", " + TextureAddressModeToString(address_mode) + ", ",
|
||||
global_address, ")");
|
||||
case TensorStorageType::IMAGE_BUFFER:
|
||||
return absl::StrCat("read_imagef(", tensor_name_, ", ", global_address,
|
||||
")");
|
||||
case TensorStorageType::UNKNOWN:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
std::string TensorCodeGenerator::ReadAsType(
|
||||
DataType type, const std::string& global_address,
|
||||
TextureAddressMode address_mode) const {
|
||||
const std::string read_as =
|
||||
type == DataType::FLOAT16 ? "read_imageh" : "read_imagef";
|
||||
switch (descriptor_.storage_type) {
|
||||
case TensorStorageType::BUFFER: {
|
||||
const std::string reading =
|
||||
absl::StrCat(tensor_name_, "[", global_address, "]");
|
||||
if (type == descriptor_.data_type) {
|
||||
return reading;
|
||||
} else {
|
||||
const std::string conversion =
|
||||
type == DataType::FLOAT16 ? "convert_half4" : "convert_float4";
|
||||
return absl::StrCat(conversion, "(", reading, ")");
|
||||
}
|
||||
}
|
||||
case TensorStorageType::TEXTURE_2D:
|
||||
case TensorStorageType::TEXTURE_3D:
|
||||
case TensorStorageType::SINGLE_TEXTURE_2D:
|
||||
case TensorStorageType::TEXTURE_ARRAY:
|
||||
return absl::StrCat(
|
||||
read_as, "(", tensor_name_,
|
||||
", " + TextureAddressModeToString(address_mode) + ", ",
|
||||
global_address, ")");
|
||||
case TensorStorageType::IMAGE_BUFFER:
|
||||
return absl::StrCat(read_as, "(", tensor_name_, ", ", global_address,
|
||||
")");
|
||||
case TensorStorageType::UNKNOWN:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
std::string TensorCodeGenerator::Write(
|
||||
const std::string& var_name, const std::string& global_address) const {
|
||||
switch (descriptor_.storage_type) {
|
||||
case TensorStorageType::BUFFER:
|
||||
case TensorStorageType::IMAGE_BUFFER:
|
||||
return absl::StrCat(tensor_name_, "[", global_address, "] = ", var_name,
|
||||
";\n");
|
||||
case TensorStorageType::TEXTURE_2D:
|
||||
case TensorStorageType::TEXTURE_3D:
|
||||
case TensorStorageType::SINGLE_TEXTURE_2D:
|
||||
case TensorStorageType::TEXTURE_ARRAY:
|
||||
return absl::StrCat(GetWriteImageFromDataType(descriptor_.data_type), "(",
|
||||
tensor_name_, ", ", global_address, ", ", var_name,
|
||||
");\n");
|
||||
case TensorStorageType::UNKNOWN:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
std::string GetTensorDeclaration(AccessType access,
|
||||
const std::string& tensor_name,
|
||||
const TensorDescriptor& descriptor) {
|
||||
switch (descriptor.storage_type) {
|
||||
case TensorStorageType::BUFFER:
|
||||
return absl::StrCat("__global ", ToCLDataType(descriptor.data_type, 4),
|
||||
"* ", tensor_name);
|
||||
case TensorStorageType::TEXTURE_2D:
|
||||
case TensorStorageType::SINGLE_TEXTURE_2D:
|
||||
return GetImageModifier(access) + " image2d_t " + tensor_name;
|
||||
case TensorStorageType::TEXTURE_ARRAY:
|
||||
return GetImageModifier(access) + " image2d_array_t " + tensor_name;
|
||||
case TensorStorageType::TEXTURE_3D:
|
||||
return GetImageModifier(access) + " image3d_t " + tensor_name;
|
||||
case TensorStorageType::IMAGE_BUFFER:
|
||||
if (access == AccessType::WRITE) {
|
||||
return absl::StrCat("__global ", ToCLDataType(descriptor.data_type, 4),
|
||||
"* ", tensor_name);
|
||||
} else {
|
||||
return GetImageModifier(access) + " image1d_buffer_t " + tensor_name;
|
||||
}
|
||||
case TensorStorageType::UNKNOWN:
|
||||
return "error";
|
||||
}
|
||||
}
|
||||
|
||||
std::string GetXStrideCorrected(const std::string& src_x,
|
||||
const std::string& batch_size,
|
||||
const std::string& stride_x,
|
||||
|
@ -36,187 +36,6 @@ namespace cl {
|
||||
|
||||
std::string GetCommonDefines(CalculationsPrecision precision);
|
||||
|
||||
struct WHSPoint {
|
||||
std::string w_name;
|
||||
std::string h_name;
|
||||
std::string s_name;
|
||||
};
|
||||
struct WHSBPoint {
|
||||
std::string w_name;
|
||||
std::string h_name;
|
||||
std::string s_name;
|
||||
std::string b_name;
|
||||
};
|
||||
struct WHDSPoint {
|
||||
std::string w_name;
|
||||
std::string h_name;
|
||||
std::string d_name;
|
||||
std::string s_name;
|
||||
};
|
||||
struct WHDSBPoint {
|
||||
std::string w_name;
|
||||
std::string h_name;
|
||||
std::string d_name;
|
||||
std::string s_name;
|
||||
std::string b_name;
|
||||
};
|
||||
|
||||
class TensorCodeGenerator {
|
||||
public:
|
||||
TensorCodeGenerator() = default;
|
||||
TensorCodeGenerator(const std::string& name, const WHSPoint& sizes,
|
||||
const TensorDescriptor& descriptor);
|
||||
TensorCodeGenerator(const std::string& name, const WHSBPoint& sizes,
|
||||
const TensorDescriptor& descriptor);
|
||||
TensorCodeGenerator(const std::string& name, const WHDSPoint& sizes,
|
||||
const TensorDescriptor& descriptor);
|
||||
TensorCodeGenerator(const std::string& name, const WHDSBPoint& sizes,
|
||||
const TensorDescriptor& descriptor);
|
||||
|
||||
std::string GetDeclaration(AccessType access) const;
|
||||
|
||||
std::string GetAddressWHS(const std::string& var_name, const std::string& x,
|
||||
const std::string& y, const std::string& s) const;
|
||||
|
||||
std::string GetAddressWHSB(const std::string& var_name, const std::string& x,
|
||||
const std::string& y, const std::string& s,
|
||||
const std::string& b) const;
|
||||
|
||||
std::string GetAddressWHDS(const std::string& var_name, const std::string& x,
|
||||
const std::string& y, const std::string& z,
|
||||
const std::string& s) const;
|
||||
|
||||
std::string GetAddressWHDSB(const std::string& var_name, const std::string& x,
|
||||
const std::string& y, const std::string& z,
|
||||
const std::string& s, const std::string& b) const;
|
||||
|
||||
// This function (and functions below) accept TextureAddressMode, but this
|
||||
// argument applicable only for texture types. Buffer types ignore this
|
||||
// parameter.
|
||||
std::string ReadWHS(
|
||||
const std::string& x, const std::string& y, const std::string& s,
|
||||
TextureAddressMode address_mode = TextureAddressMode::DONT_CARE) const;
|
||||
|
||||
std::string ReadWHSB(
|
||||
const std::string& x, const std::string& y, const std::string& s,
|
||||
const std::string& b,
|
||||
TextureAddressMode address_mode = TextureAddressMode::DONT_CARE) const;
|
||||
|
||||
std::string ReadWHDS(
|
||||
const std::string& x, const std::string& y, const std::string& z,
|
||||
const std::string& s,
|
||||
TextureAddressMode address_mode = TextureAddressMode::DONT_CARE) const;
|
||||
|
||||
std::string ReadWHDSB(
|
||||
const std::string& x, const std::string& y, const std::string& z,
|
||||
const std::string& s, const std::string& b,
|
||||
TextureAddressMode address_mode = TextureAddressMode::DONT_CARE) const;
|
||||
|
||||
// Optimization for textures, so as in opencl we can use read_imagef for any
|
||||
// texture type.
|
||||
std::string ReadAsFloatWHS(
|
||||
const std::string& x, const std::string& y, const std::string& s,
|
||||
TextureAddressMode address_mode = TextureAddressMode::DONT_CARE) const;
|
||||
|
||||
std::string ReadAsFloatWHSB(
|
||||
const std::string& x, const std::string& y, const std::string& s,
|
||||
const std::string& b,
|
||||
TextureAddressMode address_mode = TextureAddressMode::DONT_CARE) const;
|
||||
|
||||
std::string ReadAsFloatWHDS(
|
||||
const std::string& x, const std::string& y, const std::string& z,
|
||||
const std::string& s,
|
||||
TextureAddressMode address_mode = TextureAddressMode::DONT_CARE) const;
|
||||
|
||||
std::string ReadAsFloatWHDSB(
|
||||
const std::string& x, const std::string& y, const std::string& z,
|
||||
const std::string& s, const std::string& b,
|
||||
TextureAddressMode address_mode = TextureAddressMode::DONT_CARE) const;
|
||||
|
||||
// Optimization for textures, so as in opencl we can use read_imagef for any
|
||||
// texture type.
|
||||
std::string ReadAsTypeWHS(
|
||||
DataType type, const std::string& x, const std::string& y,
|
||||
const std::string& s,
|
||||
TextureAddressMode address_mode = TextureAddressMode::DONT_CARE) const;
|
||||
|
||||
std::string ReadAsTypeWHSB(
|
||||
DataType type, const std::string& x, const std::string& y,
|
||||
const std::string& s, const std::string& b,
|
||||
TextureAddressMode address_mode = TextureAddressMode::DONT_CARE) const;
|
||||
|
||||
std::string ReadAsTypeWHDS(
|
||||
DataType type, const std::string& x, const std::string& y,
|
||||
const std::string& z, const std::string& s,
|
||||
TextureAddressMode address_mode = TextureAddressMode::DONT_CARE) const;
|
||||
|
||||
std::string ReadAsTypeWHDSB(
|
||||
DataType type, const std::string& x, const std::string& y,
|
||||
const std::string& z, const std::string& s, const std::string& b,
|
||||
TextureAddressMode address_mode = TextureAddressMode::DONT_CARE) const;
|
||||
|
||||
std::string WriteWHS(const std::string& var_name, const std::string& x,
|
||||
const std::string& y, const std::string& s) const;
|
||||
|
||||
std::string WriteWHSB(const std::string& var_name, const std::string& x,
|
||||
const std::string& y, const std::string& s,
|
||||
const std::string& b) const;
|
||||
|
||||
std::string WriteWHDS(const std::string& var_name, const std::string& x,
|
||||
const std::string& y, const std::string& z,
|
||||
const std::string& s) const;
|
||||
|
||||
std::string WriteWHDSB(const std::string& var_name, const std::string& x,
|
||||
const std::string& y, const std::string& z,
|
||||
const std::string& s, const std::string& b) const;
|
||||
|
||||
std::string Read(
|
||||
const std::string& global_address,
|
||||
TextureAddressMode address_mode = TextureAddressMode::DONT_CARE) const;
|
||||
// Optimization for textures, so as in opencl we can use read_imagef for any
|
||||
// texture type.
|
||||
std::string ReadAsFloat(
|
||||
const std::string& global_address,
|
||||
TextureAddressMode address_mode = TextureAddressMode::DONT_CARE) const;
|
||||
std::string ReadAsType(
|
||||
DataType type, const std::string& global_address,
|
||||
TextureAddressMode address_mode = TextureAddressMode::DONT_CARE) const;
|
||||
std::string Write(const std::string& var_name,
|
||||
const std::string& global_address) const;
|
||||
|
||||
private:
|
||||
std::string GetGlobalAddressNoDeclarationWHS(const std::string& x,
|
||||
const std::string& y,
|
||||
const std::string& s) const;
|
||||
std::string GetGlobalAddressNoDeclarationWHSB(const std::string& x,
|
||||
const std::string& y,
|
||||
const std::string& s,
|
||||
const std::string& b) const;
|
||||
std::string GetGlobalAddressNoDeclarationWHDS(const std::string& x,
|
||||
const std::string& y,
|
||||
const std::string& z,
|
||||
const std::string& s) const;
|
||||
std::string GetGlobalAddressNoDeclarationWHDSB(const std::string& x,
|
||||
const std::string& y,
|
||||
const std::string& z,
|
||||
const std::string& s,
|
||||
const std::string& b) const;
|
||||
std::string DeclareAddress(const std::string& var_name,
|
||||
const std::string& address) const;
|
||||
|
||||
std::string tensor_name_;
|
||||
std::string width_name_ = "unknown";
|
||||
std::string height_name_ = "unknown";
|
||||
std::string depth_name_ = "unknown";
|
||||
std::string slices_name_ = "unknown";
|
||||
std::string batch_name_ = "unknown";
|
||||
TensorDescriptor descriptor_;
|
||||
};
|
||||
|
||||
std::string GetTensorDeclaration(AccessType access,
|
||||
const std::string& tensor_name,
|
||||
const TensorDescriptor& descriptor);
|
||||
|
||||
// Calculates correct X coordinate when stride != 1 and batch != 1 for layouts
|
||||
// with B after W (for example HWBC4) and WB stored in one axis of GPU
|
||||
// resources.
|
||||
|
Loading…
x
Reference in New Issue
Block a user