Skip to content
Snippets Groups Projects
Commit ccb1ecd3 authored by Felix Weiglhofer's avatar Felix Weiglhofer
Browse files

Revisit detail::image_context.

- Simplify class.
- Fix undefined-var-template warning in clang.
parent bf4b8857
No related branches found
No related tags found
No related merge requests found
......@@ -130,7 +130,8 @@ function(xpu_attach Library)
get_filename_component(KernelDeclFullPath "${KernelDecl}" REALPATH)
target_compile_definitions(${Library} PRIVATE XPU_IMAGE_FILE="${Library}")
target_compile_options(${Library} PUBLIC -fPIC -Wno-undefined-var-template)
# target_compile_options(${Library} PUBLIC -fPIC -Wno-undefined-var-template)
target_compile_options(${Library} PUBLIC -fPIC)
target_link_libraries(${Library} xpu)
if (TARGET OpenMP::OpenMP_CXX)
target_link_libraries(${Library} OpenMP::OpenMP_CXX)
......
......@@ -61,29 +61,29 @@ using action_interface_t = typename action_interface<typename A::tag, A>::type;
using symbol_table = std::vector<std::pair<std::string, void *>>;
template<typename I>
struct image_file_name {
const char *operator()() const;
};
template <typename I>
class image_context {
public:
static const char *file_name;
static std::unordered_map<std::string, size_t> &ids();
static image_context<I> *instance();
image_context() {
name = type_name<I>();
}
image_context() { name = type_name<I>(); }
symbol_table &get_symbols() { return symbols; }
std::string get_name() const { return name; }
template<typename A>
void add_symbol(void *symbol) {
auto it = ids().find(type_name<A>());
if (it == ids().end()) {
ids()[type_name<A>()] = grouped_type_id<A, typename A::image>::get();
auto it = ids.find(type_name<A>());
if (it == ids.end()) {
ids[type_name<A>()] = grouped_type_id<A, typename A::image>::get();
}
size_t id = ids()[type_name<A>()];
size_t id = ids[type_name<A>()];
if (symbols.size() <= id) {
symbols.resize(id+1);
}
......@@ -91,6 +91,7 @@ public:
}
private:
std::unordered_map<std::string, size_t> ids;
symbol_table symbols;
std::string name;
......@@ -397,17 +398,20 @@ struct register_kernel {
} // namespace xpu::detail
#if XPU_IS_CPU
#define XPU_DETAIL_TYPE_ID_MAP(image) \
template<> \
const char *xpu::detail::image_context<image>::file_name = XPU_IMAGE_FILE; \
\
template<> \
std::unordered_map<std::string, size_t> &xpu::detail::image_context<image>::ids() { \
static std::unordered_map<std::string, size_t> ids; \
return ids; \
}
#else
const char *xpu::detail::image_file_name<image>::operator()() const { return XPU_IMAGE_FILE; }
#define XPU_DETAIL_IMAGE_CONTEXT_GETTER(image)
#else // HIP OR CUDA
#define XPU_DETAIL_TYPE_ID_MAP(image)
#define XPU_DETAIL_IMAGE_CONTEXT_GETTER(image) \
extern "C" xpu::detail::image_context<image> *xpu_detail_get_context() { \
return xpu::detail::image_context<image>::instance(); \
}
#endif
#define XPU_DETAIL_IMAGE(image) \
......@@ -417,9 +421,9 @@ struct register_kernel {
static image_context<image> ctx; \
return &ctx; \
} \
extern "C" xpu::detail::image_context<image> *xpu_detail_get_context() { \
return xpu::detail::image_context<image>::instance(); \
}
XPU_DETAIL_IMAGE_CONTEXT_GETTER(image) \
void xpu_detail_dummy_func() // Force semicolon at the end of macro
#define XPU_DETAIL_EXPORT_FUNC(image, name, ...) \
struct name : xpu::detail::action<image, xpu::detail::function_tag> { \
......
......@@ -138,7 +138,7 @@ private:
break;
case cuda:
case hip:
i = new image<I>(complete_file_name(image_context<I>::file_name, d).c_str());
i = new image<I>(complete_file_name(image_file_name<I>{}(), d).c_str());
break;
}
m_images.add(i, d);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment