mirror of
https://github.com/ROCm/composable_kernel.git
synced 2026-05-20 21:09:08 +00:00
Add host lib (#1134)
* Format
* Format
* Format
* Remove const
* Use the right template
* Format
* Format
* add row/col instances
* Add missing file
* fixed
* Format
* Updates
* Format
* fixed rrr layout
* Format
* Update test and embed modules
* Restore older version
* Update year
* Set -fPIC
* Format
* Use double for isnan
* rename host folder to codegen + minor fix
* add codegen CI test
* add option to build components without building CK
* fix the groovy syntax
* fix typo
* use the correct function for the codegen stage
---------
Co-authored-by: Jing Zhang <jizha@amd.com>
Co-authored-by: Illia Silin <98187287+illsilin@users.noreply.github.com>
Co-authored-by: illsilin <Illia.Silin@amd.com>
[ROCm/composable_kernel commit: 8eff4d62b6]
This commit is contained in:
27
codegen/test/rtc/include/rtc/compile_kernel.hpp
Normal file
27
codegen/test/rtc/include/rtc/compile_kernel.hpp
Normal file
@@ -0,0 +1,27 @@
|
||||
#ifndef GUARD_HOST_TEST_RTC_INCLUDE_RTC_COMPILE_KERNEL
|
||||
#define GUARD_HOST_TEST_RTC_INCLUDE_RTC_COMPILE_KERNEL
|
||||
|
||||
#include <rtc/kernel.hpp>
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
|
||||
namespace rtc {
|
||||
|
||||
struct src_file
|
||||
{
|
||||
std::filesystem::path path;
|
||||
std::string_view content;
|
||||
};
|
||||
|
||||
struct compile_options
|
||||
{
|
||||
std::string flags = "";
|
||||
std::string kernel_name = "main";
|
||||
};
|
||||
|
||||
kernel compile_kernel(const std::vector<src_file>& src,
|
||||
compile_options options = compile_options{});
|
||||
|
||||
} // namespace rtc
|
||||
|
||||
#endif
|
||||
78
codegen/test/rtc/include/rtc/hip.hpp
Normal file
78
codegen/test/rtc/include/rtc/hip.hpp
Normal file
@@ -0,0 +1,78 @@
|
||||
#ifndef GUARD_HOST_TEST_RTC_INCLUDE_RTC_HIP
|
||||
#define GUARD_HOST_TEST_RTC_INCLUDE_RTC_HIP
|
||||
|
||||
#include <hip/hip_runtime_api.h>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
namespace rtc {
|
||||
|
||||
template <class T>
|
||||
struct buffer
|
||||
{
|
||||
buffer() : ptr(), n(0) {}
|
||||
buffer(std::shared_ptr<T> p, std::size_t sz) : ptr(p), n(sz) {}
|
||||
buffer(std::shared_ptr<void> p, std::size_t sz)
|
||||
: ptr(std::reinterpret_pointer_cast<T>(p)), n(sz)
|
||||
{
|
||||
}
|
||||
explicit buffer(std::size_t sz) : ptr(new T[sz]), n(sz) {}
|
||||
T* begin() { return data(); }
|
||||
T* end() { return data() + size(); }
|
||||
const T* begin() const { return data(); }
|
||||
const T* end() const { return data() + size(); }
|
||||
|
||||
T& front() { return data()[0]; }
|
||||
T& back() { return data()[size() - 1]; }
|
||||
T& operator[](std::size_t i) { return data()[i]; }
|
||||
T& at(std::size_t i)
|
||||
{
|
||||
if(i >= size())
|
||||
throw std::runtime_error("Out of bounds");
|
||||
return data()[i];
|
||||
}
|
||||
|
||||
const T& front() const { return data()[0]; }
|
||||
const T& back() const { return data()[size() - 1]; }
|
||||
const T& operator[](std::size_t i) const { return data()[i]; }
|
||||
const T& at(std::size_t i) const
|
||||
{
|
||||
if(i >= size())
|
||||
throw std::runtime_error("Out of bounds");
|
||||
return data()[i];
|
||||
}
|
||||
const T* data() const { return ptr.get(); }
|
||||
T* data() { return ptr.get(); }
|
||||
|
||||
std::size_t size() const { return n; }
|
||||
std::size_t bytes() const { return size() * sizeof(T); }
|
||||
|
||||
bool empty() const { return size() == 0; }
|
||||
|
||||
private:
|
||||
std::shared_ptr<T> ptr;
|
||||
std::size_t n;
|
||||
};
|
||||
|
||||
std::string get_device_name();
|
||||
std::string hip_error(int error);
|
||||
|
||||
std::shared_ptr<void> allocate_gpu(std::size_t sz, bool host = false);
|
||||
std::shared_ptr<void> write_to_gpu(const void* x, std::size_t sz, bool host = false);
|
||||
std::shared_ptr<void> read_from_gpu(const void* x, std::size_t sz);
|
||||
|
||||
template <class T>
|
||||
buffer<T> to_gpu(const buffer<T>& input)
|
||||
{
|
||||
return {write_to_gpu(input.data(), input.bytes()), input.size()};
|
||||
}
|
||||
|
||||
template <class T>
|
||||
buffer<T> from_gpu(const buffer<T>& input)
|
||||
{
|
||||
return {read_from_gpu(input.data(), input.bytes()), input.size()};
|
||||
}
|
||||
|
||||
} // namespace rtc
|
||||
|
||||
#endif
|
||||
62
codegen/test/rtc/include/rtc/kernel.hpp
Normal file
62
codegen/test/rtc/include/rtc/kernel.hpp
Normal file
@@ -0,0 +1,62 @@
|
||||
#ifndef GUARD_HOST_TEST_RTC_INCLUDE_RTC_KERNEL
|
||||
#define GUARD_HOST_TEST_RTC_INCLUDE_RTC_KERNEL
|
||||
|
||||
#include <hip/hip_runtime_api.h>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace rtc {
|
||||
|
||||
struct kernel_argument
|
||||
{
|
||||
template <class T,
|
||||
class U = std::remove_reference_t<T>,
|
||||
class = std::enable_if_t<not std::is_base_of<kernel_argument, T>{}>>
|
||||
kernel_argument(T&& x) : size(sizeof(U)), align(alignof(U)), data(&x) // NOLINT
|
||||
{
|
||||
}
|
||||
std::size_t size;
|
||||
std::size_t align;
|
||||
void* data;
|
||||
};
|
||||
|
||||
std::vector<char> pack_args(const std::vector<kernel_argument>& args);
|
||||
|
||||
struct kernel_impl;
|
||||
|
||||
struct kernel
|
||||
{
|
||||
kernel() = default;
|
||||
kernel(const char* image, const std::string& name);
|
||||
template <class T>
|
||||
kernel(const std::vector<T>& image, const std::string& name)
|
||||
: kernel(reinterpret_cast<const char*>(image.data()), name)
|
||||
{
|
||||
static_assert(sizeof(T) == 1, "Only byte types");
|
||||
}
|
||||
|
||||
void launch(hipStream_t stream,
|
||||
std::size_t global,
|
||||
std::size_t local,
|
||||
const std::vector<kernel_argument>& args) const;
|
||||
|
||||
void launch(hipStream_t stream,
|
||||
std::size_t global,
|
||||
std::size_t local,
|
||||
std::vector<void*> args) const;
|
||||
|
||||
template <class... Ts>
|
||||
auto launch(hipStream_t stream, std::size_t global, std::size_t local, Ts... zs) const
|
||||
{
|
||||
return [=](auto&&... xs) {
|
||||
launch(stream, global, local, std::vector<kernel_argument>{xs...}, zs...);
|
||||
};
|
||||
}
|
||||
|
||||
private:
|
||||
std::shared_ptr<kernel_impl> impl;
|
||||
};
|
||||
} // namespace rtc
|
||||
|
||||
#endif
|
||||
55
codegen/test/rtc/include/rtc/manage_ptr.hpp
Normal file
55
codegen/test/rtc/include/rtc/manage_ptr.hpp
Normal file
@@ -0,0 +1,55 @@
|
||||
#ifndef GUARD_HOST_TEST_RTC_INCLUDE_RTC_MANAGE_POINTER
|
||||
#define GUARD_HOST_TEST_RTC_INCLUDE_RTC_MANAGE_POINTER
|
||||
|
||||
#include <type_traits>
|
||||
#include <memory>
|
||||
|
||||
namespace rtc {
|
||||
template <class F, F f>
|
||||
struct manage_deleter
|
||||
{
|
||||
template <class T>
|
||||
void operator()(T* x) const
|
||||
{
|
||||
if(x != nullptr)
|
||||
{
|
||||
(void)f(x);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
struct null_deleter
|
||||
{
|
||||
template <class T>
|
||||
void operator()(T*) const
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
template <class T, class F, F f>
|
||||
using manage_ptr = std::unique_ptr<T, manage_deleter<F, f>>;
|
||||
|
||||
template <class T>
|
||||
struct element_type
|
||||
{
|
||||
using type = typename T::element_type;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
using remove_ptr = typename std::
|
||||
conditional_t<std::is_pointer<T>{}, std::remove_pointer<T>, element_type<T>>::type;
|
||||
|
||||
template <class T>
|
||||
using shared = std::shared_ptr<remove_ptr<T>>;
|
||||
|
||||
template <class T>
|
||||
shared<T> share(T p)
|
||||
{
|
||||
return shared<T>{std::move(p)};
|
||||
}
|
||||
|
||||
#define RTC_MANAGE_PTR(T, F) rtc::manage_ptr<std::remove_pointer_t<T>, decltype(&F), &F>
|
||||
|
||||
} // namespace rtc
|
||||
|
||||
#endif
|
||||
24
codegen/test/rtc/include/rtc/tmp_dir.hpp
Normal file
24
codegen/test/rtc/include/rtc/tmp_dir.hpp
Normal file
@@ -0,0 +1,24 @@
|
||||
#ifndef GUARD_HOST_TEST_RTC_INCLUDE_RTC_TMP_DIR
|
||||
#define GUARD_HOST_TEST_RTC_INCLUDE_RTC_TMP_DIR
|
||||
|
||||
#include <string>
|
||||
#include <filesystem>
|
||||
|
||||
namespace rtc {
|
||||
|
||||
struct tmp_dir
|
||||
{
|
||||
std::filesystem::path path;
|
||||
tmp_dir(const std::string& prefix = "");
|
||||
|
||||
void execute(const std::string& cmd) const;
|
||||
|
||||
tmp_dir(tmp_dir const&) = delete;
|
||||
tmp_dir& operator=(tmp_dir const&) = delete;
|
||||
|
||||
~tmp_dir();
|
||||
};
|
||||
|
||||
} // namespace rtc
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user