@@ -56,8 +56,13 @@ endmacro()
|
||||
string(APPEND NVRTC_INCLUDES_STRINGS "char const *kCutlassHeaders[] = {\n")
|
||||
string(APPEND NVRTC_INCLUDES_NAMES "char const *kCutlassHeaderNames[] = {\n")
|
||||
|
||||
|
||||
file(GLOB_RECURSE NVRTC_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} kernel/thread/*.hpp)
|
||||
|
||||
add_nvrtc_headers(${PROJECT_SOURCE_DIR}/include "${CUTLASS_CUTLASS};${CUTLASS_UTIL};${CUTLASS_DEVICE}")
|
||||
add_nvrtc_headers(${PROJECT_SOURCE_DIR}/include "${CUTLASS_CUTE}")
|
||||
add_nvrtc_headers(${PROJECT_SOURCE_DIR}/test "${CUTLASS_NVRTC};${CUTLASS_UTIL};${CUTLASS_DEVICE}")
|
||||
add_nvrtc_headers(${CMAKE_CURRENT_SOURCE_DIR} "${NVRTC_SOURCES}")
|
||||
|
||||
add_nvrtc_headers("${CMAKE_CURRENT_SOURCE_DIR}/stdlib" "assert.h;stdint.h")
|
||||
if(CUTLASS_NVRTC_HAS_CUDA_FP16)
|
||||
|
||||
@@ -0,0 +1,127 @@
|
||||
/***************************************************************************************************
|
||||
* Copyright (c) 2017 - 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
**************************************************************************************************/
|
||||
|
||||
#include "cute/tensor.hpp"
|
||||
#include "cutlass/epilogue/thread/linear_combination.h"
|
||||
#include "cutlass/gemm/collective/collective_builder.hpp"
|
||||
#include "cutlass/gemm/kernel/gemm_universal.hpp"
|
||||
#include "cutlass/epilogue/collective/default_epilogue.hpp"
|
||||
|
||||
|
||||
namespace nvrtc {
|
||||
namespace thread {
|
||||
|
||||
template<
|
||||
typename ElementA, typename ElementB, typename ElementC,
|
||||
typename TileShape, typename ClusterShape,
|
||||
bool kTransA, bool kTransB,
|
||||
int RANK_M, int RANK_N, int RANK_K, int RANK_L
|
||||
>
|
||||
struct ContractionKernel {
|
||||
|
||||
using ElementScalar = float;
|
||||
using ElementAccum = float;
|
||||
using EpilogueThread = cutlass::epilogue::thread::LinearCombination<ElementC,
|
||||
1,
|
||||
ElementAccum,
|
||||
ElementScalar>;
|
||||
|
||||
static constexpr cute::GMMA::Major majorA = ! kTransA ? cute::GMMA::Major::MN : cute::GMMA::Major::K;
|
||||
static constexpr cute::GMMA::Major majorB = ! kTransB ? cute::GMMA::Major::K : cute::GMMA::Major::MN;
|
||||
|
||||
/// Kernel config
|
||||
typedef int64_t stride_type;
|
||||
typedef int32_t extent_type;
|
||||
|
||||
static constexpr const stride_type* stride_null = nullptr;
|
||||
static constexpr const extent_type* extent_null = nullptr;
|
||||
|
||||
template <int Rank, bool IsMajor, class Indexable>
|
||||
static constexpr
|
||||
auto
|
||||
make_stride_tuple(Indexable const& t, int n, int64_t init_default = 0) {
|
||||
static_assert(Rank > 1);
|
||||
if constexpr (IsMajor) {
|
||||
return cute::transform(cute::make_seq<Rank>{}, [&](auto i) {
|
||||
if constexpr (i == 0) {
|
||||
return cute::Int<1>{};
|
||||
}
|
||||
else {
|
||||
return i < n ? t[i] : init_default;
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
return cute::make_int_tuple<Rank>(t, n, init_default);
|
||||
}
|
||||
}
|
||||
|
||||
using StrideA = decltype(cute::make_stride(
|
||||
make_stride_tuple<RANK_M, majorA == cute::GMMA::Major::MN>(stride_null, 0, 0),
|
||||
make_stride_tuple<RANK_K, majorA == cute::GMMA::Major::K>(stride_null, 0, 0),
|
||||
cute::make_int_tuple<RANK_L>(stride_null, 0, 0)));
|
||||
|
||||
using StrideB = decltype(cute::make_stride(
|
||||
make_stride_tuple<RANK_N, majorB == cute::GMMA::Major::MN>(stride_null, 0, 0),
|
||||
make_stride_tuple<RANK_K, majorB == cute::GMMA::Major::K>(stride_null, 0, 0),
|
||||
cute::make_int_tuple<RANK_L>(stride_null, 0, 0)));
|
||||
|
||||
using StrideC = decltype(cute::make_stride(
|
||||
cute::make_int_tuple<RANK_M>(stride_null, 0, 0),
|
||||
cute::make_int_tuple<RANK_N>(stride_null, 0, 0),
|
||||
cute::make_int_tuple<RANK_L>(stride_null, 0, 0)));
|
||||
|
||||
using ProblemShape = decltype(cute::make_shape(
|
||||
cute::make_int_tuple<RANK_M>(extent_null, 0, 0),
|
||||
cute::make_int_tuple<RANK_N>(extent_null, 0, 0),
|
||||
cute::make_int_tuple<RANK_K>(extent_null, 0, 0),
|
||||
cute::make_int_tuple<RANK_L>(extent_null, 0, 0)));
|
||||
|
||||
using CollectiveOp = typename cutlass::gemm::collective::CollectiveBuilder<
|
||||
cutlass::arch::Sm90, cutlass::arch::OpClassTensorOp,
|
||||
ElementA, StrideA, 16 / sizeof(ElementA),
|
||||
ElementB, StrideB, 16 / sizeof(ElementB),
|
||||
ElementAccum,
|
||||
TileShape, ClusterShape, cutlass::gemm::collective::StageCountAuto,
|
||||
cutlass::gemm::KernelTmaWarpSpecialized
|
||||
>::CollectiveOp;
|
||||
|
||||
using EpilogueOutputOp = cutlass::epilogue::collective::DefaultEpilogue<StrideC, StrideC, EpilogueThread, cutlass::gemm::EpilogueDefault>;
|
||||
using CollectiveEpilogue = cutlass::epilogue::collective::detail::Sm90TmaWarpSpecializedAdapter<EpilogueOutputOp>;
|
||||
using Kernel = cutlass::gemm::kernel::GemmUniversal<
|
||||
ProblemShape,
|
||||
CollectiveOp,
|
||||
CollectiveEpilogue>;
|
||||
|
||||
};
|
||||
|
||||
} // namespace nvrtc
|
||||
} // namespace thread
|
||||
@@ -0,0 +1 @@
|
||||
nvrtc_config.hpp
|
||||
@@ -26,10 +26,15 @@
|
||||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
configure_file(nvrtc_config.in nvrtc_config.hpp)
|
||||
|
||||
cutlass_test_unit_add_executable(
|
||||
cutlass_test_unit_nvrtc_thread
|
||||
gemm_nvrtc.cu
|
||||
nvrtc_gemm.cu
|
||||
nvrtc_contraction.cu
|
||||
testbed.h
|
||||
)
|
||||
)
|
||||
|
||||
target_link_libraries(cutlass_test_unit_nvrtc_thread PRIVATE cutlass_nvrtc)
|
||||
|
||||
target_include_directories(cutlass_test_unit_nvrtc_thread PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
#pragma once
|
||||
|
||||
#define CUDA_INCLUDE_DIR "@CUDA_TOOLKIT_ROOT_DIR@/include"
|
||||
@@ -0,0 +1,66 @@
|
||||
/***************************************************************************************************
|
||||
* Copyright (c) 2017 - 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
**************************************************************************************************/
|
||||
/*! \file
|
||||
\brief Unit tests for GETT
|
||||
*/
|
||||
|
||||
#include <cuda.h>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "testbed.h"
|
||||
|
||||
#include "nvrtc_config.hpp"
|
||||
|
||||
#ifndef CUDA_INCLUDE_DIR
|
||||
static_assert(0, "CUDA include path is not defined");
|
||||
#endif
|
||||
|
||||
TEST(SM90_nvrtc_kernel, Contraction) {
|
||||
static const char* nvrtc_opts[] = {
|
||||
"-w",
|
||||
"-default-device",
|
||||
"-std=c++17",
|
||||
"-arch=sm_90",
|
||||
"-I" CUDA_INCLUDE_DIR,
|
||||
};
|
||||
|
||||
EXPECT_TRUE(test::nvrtc::thread::TestbedKernel::compile(
|
||||
"nvrtc::thread::ContractionKernel<"
|
||||
"cutlass::bfloat16_t, cutlass::bfloat16_t, cutlass::bfloat16_t,"
|
||||
"cute::Shape<cute::Shape<cute::_8, cute::_8>, cute::Shape<cute::_16, cute::_8>, cute::Shape<cute::_8, cute::_8>>,"
|
||||
"cute::Shape<cute::_1, cute::_2, cute::_1>,"
|
||||
"true, true,"
|
||||
"10, 10, 10, 10>::Kernel",
|
||||
{ nvrtc_opts, nvrtc_opts + 5 }
|
||||
));
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -35,12 +35,15 @@
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <cstdio>
|
||||
#include <vector>
|
||||
|
||||
#include "cutlass/gemm/thread/mma.h"
|
||||
#include "../kernel/thread/testbed_kernel.h"
|
||||
|
||||
#include "cutlass/util/host_tensor.h"
|
||||
#include "cutlass/util/tensor_view_io.h"
|
||||
#include "cutlass/trace.h"
|
||||
|
||||
#include "cutlass/util/reference/host/tensor_copy.h"
|
||||
#include "cutlass/util/reference/host/tensor_fill.h"
|
||||
@@ -58,6 +61,78 @@ namespace test {
|
||||
namespace nvrtc {
|
||||
namespace thread {
|
||||
|
||||
#define NVRTC_RETURN_IF_ERROR(api) \
|
||||
do { \
|
||||
nvrtcResult _result = api; \
|
||||
if (_result != NVRTC_SUCCESS) { \
|
||||
CUTLASS_TRACE_HOST("Nvrtc error: " << _result); \
|
||||
return false; \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
inline const char * cuda_source_fmt = R"""(
|
||||
|
||||
#include "kernel/thread/contraction.hpp"
|
||||
|
||||
using Operator = %s;
|
||||
|
||||
extern "C" __global__ void global_entry(__grid_constant__ Operator::Params const params) {
|
||||
extern __shared__ char smem[];
|
||||
|
||||
Operator op;
|
||||
op(params, smem);
|
||||
}
|
||||
|
||||
)""";
|
||||
|
||||
struct TestbedKernel {
|
||||
static bool compile(std::string const &kernel, std::vector<const char *> const &opts) {
|
||||
int sz = std::snprintf(nullptr, 0, cuda_source_fmt, kernel.c_str());
|
||||
std::vector<char> cuda_source(sz + 1);
|
||||
std::snprintf(&cuda_source[0], cuda_source.size(), cuda_source_fmt, kernel.c_str());
|
||||
|
||||
nvrtcProgram program;
|
||||
NVRTC_RETURN_IF_ERROR(
|
||||
nvrtcCreateProgram(
|
||||
&program,
|
||||
cuda_source.data(),
|
||||
nullptr,
|
||||
static_cast<int32_t>(cutlass::nvrtc::kCutlassHeaderCount),
|
||||
cutlass::nvrtc::kCutlassHeaders,
|
||||
cutlass::nvrtc::kCutlassHeaderNames)
|
||||
);
|
||||
|
||||
nvrtcResult compile_result =
|
||||
nvrtcCompileProgram(
|
||||
program,
|
||||
static_cast<int32_t>(opts.size()),
|
||||
opts.data());
|
||||
|
||||
size_t log_size;
|
||||
NVRTC_RETURN_IF_ERROR(
|
||||
nvrtcGetProgramLogSize(program, &log_size)
|
||||
);
|
||||
|
||||
if (log_size > 1) {
|
||||
auto log = std::make_unique<char[]>(log_size);
|
||||
|
||||
NVRTC_RETURN_IF_ERROR(
|
||||
nvrtcGetProgramLog(program, log.get())
|
||||
);
|
||||
|
||||
std::cout << log.get() << std::endl;
|
||||
}
|
||||
|
||||
NVRTC_RETURN_IF_ERROR(compile_result);
|
||||
|
||||
NVRTC_RETURN_IF_ERROR(
|
||||
nvrtcDestroyProgram(&program)
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
/// Structure to compute the matrix product
|
||||
template <
|
||||
/// Size of the Gemm problem - concept: gemm::GemmShape<>
|
||||
|
||||
Reference in New Issue
Block a user