Skip to content

Commit

Permalink
xe: compute: kernel_ctx: add duplication check
Browse files Browse the repository at this point in the history
  • Loading branch information
echeresh committed Jan 29, 2025
1 parent 195b941 commit fa75d56
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions src/gpu/intel/compute/kernel_ctx.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2019-2024 Intel Corporation
* Copyright 2019-2025 Intel Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -78,7 +78,7 @@ class kernel_ctx_t {
void use_int32_offset(bool value) { use_int32_offset_ = value; }

void define_int(const char *variable, int64_t value) {
int_var_map_.insert({variable, value});
set_macro(variable, value, int_var_map_);
}

void define_int(const std::string &variable, int64_t value) {
Expand Down Expand Up @@ -121,13 +121,6 @@ class kernel_ctx_t {
}
}

template <typename T>
T get_scalar(const std::string &s) const {
UNUSED(s);
static_assert(!std::is_same<T, T>::value, "not expected");
return {};
}

std::string data_type() const {
if (int_var_map_.count("DT_F16") != 0) return "f16";

Expand Down Expand Up @@ -179,19 +172,23 @@ class kernel_ctx_t {
if (attr) { define_int("DETERMINISTIC", attr->deterministic_); }
}

template <typename T>
void set_macro(const char *variable, const T &value,
std::map<std::string, T> &var_map) {
gpu_assert(var_map.count(variable) == 0 || var_map[variable] == value)
<< "Error: macro " << variable
<< " is already set to a different value.\n Old value: "
<< var_map[variable] << "\n New value: " << value;
var_map.insert({variable, value});
}

std::map<std::string, int64_t> int_var_map_;
std::map<std::string, float> float_var_map_;
std::set<std::string> option_set_;
std::unordered_map<std::string, std::string> custom_headers_;
bool use_int32_offset_ = true;
};

template <>
inline int64_t kernel_ctx_t::get_scalar(const std::string &name) const {
assert(int_var_map_.count(name) != 0 && "not expected");
return int_var_map_.at(name);
}

} // namespace compute
} // namespace intel
} // namespace gpu
Expand Down

0 comments on commit fa75d56

Please sign in to comment.