cudnn_frontend_MatMulDesc.h
Go to the documentation of this file.
/*
* Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved.
*
* 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:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* 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.
*/
#pragma once
#include <algorithm>
#include <array>
#include <functional>
#include <memory>
#include <sstream>
#include <utility>
#include <cudnn.h>
#include <cudnn_backend.h>
#include "cudnn_frontend_utils.h"
namespace cudnn_frontend {
class MatMulDesc_v8 : public BackendDescriptor {
public:
friend class MatMulDescBuilder_v8;
std::string
describe() const override {
std::stringstream ss;
ss << "CUDNN_BACKEND_MATMUL_DESCRIPTOR :"
<< " Math precision " << (math_precision);
return ss.str();
}
MatMulDesc_v8(MatMulDesc_v8 &&from) = default;
MatMulDesc_v8 &
operator= (MatMulDesc_v8 &&from) = default;
~MatMulDesc_v8() = default;
private:
MatMulDesc_v8() = default;
MatMulDesc_v8(MatMulDesc_v8 const &) = delete;
MatMulDesc_v8 &
operator=(MatMulDesc_v8 const &) = delete;
cudnnDataType_t math_precision = CUDNN_DATA_FLOAT;
};
class MatMulDescBuilder_v8 {
public:
auto
setMathPrecision(cudnnDataType_t data_type_) -> MatMulDescBuilder_v8 & {
m_matMulDesc.math_precision = data_type_;
return *this;
}
MatMulDesc_v8 &&
build() {
// Create a descriptor. Memory allocation happens here.
auto status = m_matMulDesc.initialize_managed_backend_pointer(CUDNN_BACKEND_MATMUL_DESCRIPTOR);
if (status != CUDNN_STATUS_SUCCESS) {
set_error_and_throw_exception(&m_matMulDesc, status, "CUDNN_BACKEND_MATMUL_DESCRIPTOR: cudnnCreate Failed");
return std::move(m_matMulDesc);
}
// Once Created lets set the descriptor parameters.
status = cudnnBackendSetAttribute(m_matMulDesc.pointer->get_backend_descriptor(),
CUDNN_ATTR_MATMUL_COMP_TYPE,
CUDNN_TYPE_DATA_TYPE,
1,
&m_matMulDesc.math_precision);
if (status != CUDNN_STATUS_SUCCESS) {
set_error_and_throw_exception(
&m_matMulDesc,
status,
"CUDNN_BACKEND_MATMUL_DESCRIPTOR: SetAttribute CUDNN_ATTR_MATMUL_COMP_TYPE Failed");
return std::move(m_matMulDesc);
}
// Finalizing the descriptor
status = cudnnBackendFinalize(m_matMulDesc.pointer->get_backend_descriptor());
if (status != CUDNN_STATUS_SUCCESS) {
set_error_and_throw_exception(&m_matMulDesc, status, "CUDNN_BACKEND_MATMUL_DESCRIPTOR: cudnnFinalize Failed");
return std::move(m_matMulDesc);
}
getLogger() << "[cudnn_frontend] " << m_matMulDesc << std::endl;
return std::move(m_matMulDesc);
}
explicit MatMulDescBuilder_v8() = default;
~MatMulDescBuilder_v8() = default;
MatMulDescBuilder_v8(MatMulDescBuilder_v8 &&) = delete;
MatMulDescBuilder_v8(MatMulDescBuilder_v8 const &) = delete;
MatMulDescBuilder_v8 &
operator=(MatMulDescBuilder_v8 const &) = delete;
private:
MatMulDesc_v8 m_matMulDesc;
};
}
cudnn_frontend::getLogger
ConditionalStreamer & getLogger()
Definition: cudnn_frontend_Logging.h:72
cudnn_frontend::set_error_and_throw_exception
static void set_error_and_throw_exception(BackendDescriptor const *desc, cudnnStatus_t status, const char *message)
Definition: cudnn_frontend_utils.h:138
cudnn_frontend::MatMulDescBuilder_v8
Definition: cudnn_frontend_MatMulDesc.h:76
cudnn_frontend::MatMulDescBuilder_v8::build
MatMulDesc_v8 && build()
Definition: cudnn_frontend_MatMulDesc.h:93
cudnn_frontend::BackendDescriptor
Definition: cudnn_backend_base.h:99
cudnn_frontend::MatMulDesc_v8::math_precision
cudnnDataType_t math_precision
Definition: cudnn_frontend_MatMulDesc.h:70
cudnn_frontend_utils.h
cudnn_frontend::MatMulDesc_v8::describe
std::string describe() const override
Return a string describing the backend Descriptor.
Definition: cudnn_frontend_MatMulDesc.h:51
cudnn_frontend::MatMulDesc_v8::~MatMulDesc_v8
~MatMulDesc_v8()=default
cudnn_frontend::MatMulDesc_v8::MatMulDescBuilder_v8
friend class MatMulDescBuilder_v8
Definition: cudnn_frontend_MatMulDesc.h:49
cudnn_frontend::MatMulDescBuilder_v8::setMathPrecision
auto setMathPrecision(cudnnDataType_t data_type_) -> MatMulDescBuilder_v8 &
Set Math Precision Data Type for the Matmul Operation.
Definition: cudnn_frontend_MatMulDesc.h:84
cudnn_frontend::MatMulDesc_v8::MatMulDesc_v8
MatMulDesc_v8()=default
cudnn_frontend
Definition: cudnn_backend_base.h:29
cudnn_frontend::MatMulDesc_v8
Definition: cudnn_frontend_MatMulDesc.h:47
cudnn_frontend::MatMulDescBuilder_v8::m_matMulDesc
MatMulDesc_v8 m_matMulDesc
Definition: cudnn_frontend_MatMulDesc.h:134
cudnn_frontend::MatMulDesc_v8::operator=
MatMulDesc_v8 & operator=(MatMulDesc_v8 &&from)=default
cudnn_frontend::BackendDescriptor::status
cudnnStatus_t status
Shared pointer of the OpaqueBackendPointer.
Definition: cudnn_backend_base.h:160