diff --git a/experimental/builder/include/ck_tile/builder/testing/conv_fwd.hpp b/experimental/builder/include/ck_tile/builder/testing/conv_fwd.hpp index 5538716cff..435b881ed9 100644 --- a/experimental/builder/include/ck_tile/builder/testing/conv_fwd.hpp +++ b/experimental/builder/include/ck_tile/builder/testing/conv_fwd.hpp @@ -9,6 +9,7 @@ #include "ck_tile/builder/testing/testing.hpp" #include "ck_tile/builder/testing/extent.hpp" #include "ck_tile/builder/testing/tensor_buffer.hpp" +#include "ck_tile/builder/testing/tensor_initialization.hpp" #include "ck/library/utility/convolution_parameter.hpp" #include "ck/library/utility/convolution_host_tensor_descriptor_helper.hpp" /// This file implements common functionality for invoking/testing grouped diff --git a/experimental/builder/include/ck_tile/builder/testing/tensor_initialization.hpp b/experimental/builder/include/ck_tile/builder/testing/tensor_initialization.hpp new file mode 100644 index 0000000000..68cc9e57c3 --- /dev/null +++ b/experimental/builder/include/ck_tile/builder/testing/tensor_initialization.hpp @@ -0,0 +1,91 @@ +// Copyright (c) advanced Micro Devices, Inc. All rights reserved. +// SPDX-License-Identifier: MIT + +#pragma once + +#include +#include +#include +#include +#include +#include +#include "ck_tile/builder/conv_signature_concepts.hpp" +#include "ck_tile/builder/factory/helpers/ck/conv_tensor_type.hpp" +#include "ck_tile/builder/testing/type_traits.hpp" +#include "ck_tile/host/host_tensor.hpp" +#include "ck/utility/data_type.hpp" + +#include "ck/library/utility/device_tensor_generator.hpp" + +namespace ck_tile::builder::test { + +template +void init_tensor_buffer_uniform(const DeviceBuffer& buf, const TensorDescriptor
& descriptor, int min_val, int max_val) +{ + size_t size = descriptor.get_element_space_size_in_bytes(); + + if(size % sizeof(DT) != 0) + { + throw std::runtime_error("size must be a multiple of datatype size"); + } + if(max_val - min_val <= 1) + { + throw std::runtime_error("Error while filling device tensor with random integer data: max " + "value must be at least 2 greater than min value, otherwise " + "tensor will be filled by a constant value (end is exclusive)"); + } + + using ck_type = factory::internal::DataTypeToCK
::type; + + // we might be asked to generate int values on fp data types that don't have the required precision + if(static_cast(max_val - 1) == static_cast(min_val)) + { + throw std::runtime_error("Error while filling device tensor with random integer data: " + "insufficient precision in specified range"); + } + size_t packed_size = ck::packed_size_v; + fill_tensor_uniform_rand_int_values<<<256, 256>>>( + static_cast(buf.get()), min_val, max_val, (size * packed_size) / sizeof(ck_type)); +} + + +template +void init_tensor_buffer_uniform(const DeviceBuffer& buf, const TensorDescriptor
& descriptor, float min_value, float max_value) +{ + size_t size = descriptor.get_element_space_size_in_bytes(); + + if(size % sizeof(DT) != 0) + { + throw std::runtime_error("size must be a multiple of datatype size"); + } + using ck_type = factory::internal::DataTypeToCK
::type; + + if(std::nextafter(static_cast(min_value), static_cast(max_value)) >= max_value) + { + // nextafter is not defined for non-standard data types, skip test for now + // throw std::runtime_error("Error while filling device tensor with random integer data: + // insufficient precision in specified range"); + } + + size_t packed_size = ck::packed_size_v; + fill_tensor_uniform_rand_fp_values<<<256, 256>>>( + static_cast(buf.get()), min_value, max_value, (size * packed_size) / sizeof(ck_type)); +} + +template +void init_tensor_buffer_normal_fp(const DeviceBuffer& buf, const TensorDescriptor
& descriptor, float sigma, float mean) +{ + size_t size = descriptor.get_element_space_size_in_bytes(); + + if(size % sizeof(DT) != 0) + { + throw std::runtime_error("size must be a multiple of datatype size"); + } + using ck_type = factory::internal::DataTypeToCK
::type; + size_t packed_size = ck::packed_size_v; + fill_tensor_norm_rand_fp_values<<<256, 256>>>( + static_cast(buf.get()), sigma, mean, (size * packed_size) / sizeof(ck_type)); + +} + +} // namespace ck_tile::builder::test