未验证 提交 ad8847aa 编写于 作者: Q Qi Li 提交者: GitHub

[NPU] update npu prop, test=develop (#47859)

* [NPU] update npu prop, test=develop

* remove ddim.h

* remove diff

* update storage prop, test=develop
上级 b68e0c47
......@@ -263,6 +263,10 @@ template const NPUStorageProperties& DenseTensor::storage_properties() const;
template const OneDNNStorageProperties& DenseTensor::storage_properties() const;
#endif
bool DenseTensor::storage_properties_initialized() const {
return storage_properties_ != nullptr;
}
void DenseTensor::set_storage_properties(
std::unique_ptr<StorageProperties>&& storage_properties) {
storage_properties_ = std::move(storage_properties);
......
......@@ -164,6 +164,10 @@ class DenseTensor : public TensorBase,
void* data();
/// \brief Get whether the storage_properties is inited.
/// \return The init status of storage_properties.
bool storage_properties_initialized() const;
/// \brief Returns the storage_properties of the tensor.
/// \return The storage_properties of the tensor.
template <typename DeviceT>
......
......@@ -16,6 +16,7 @@ limitations under the License. */
#include <memory>
#include "paddle/phi/core/ddim.h"
#include "paddle/phi/core/utils/type_registry.h"
#ifdef PADDLE_WITH_MKLDNN
......@@ -42,8 +43,8 @@ struct NPUStorageProperties
virtual ~NPUStorageProperties() = default;
static const char* name() { return "NPUStorageProperties"; }
int64_t storage_format;
int64_t storage_layout;
int64_t storage_format{-1};
DDim storage_dims;
};
// Add OneDNNStorageProperties firstly for unittest covergae
......@@ -76,8 +77,8 @@ static std::unique_ptr<StorageProperties> CopyStorageProperties(
auto result = std::make_unique<NPUStorageProperties>();
result->storage_format =
static_cast<NPUStorageProperties*>(sp.get())->storage_format;
result->storage_layout =
static_cast<NPUStorageProperties*>(sp.get())->storage_layout;
result->storage_dims =
static_cast<NPUStorageProperties*>(sp.get())->storage_dims;
return result;
#ifdef PADDLE_WITH_MKLDNN
} else if (OneDNNStorageProperties::classof(sp.get())) {
......
......@@ -154,13 +154,15 @@ TEST(dense_tensor, storage_properties) {
EXPECT_TRUE(caught_exception);
// test custom device storage properties
EXPECT_FALSE(tensor.storage_properties_initialized());
auto npu_properties = std::make_unique<NPUStorageProperties>();
npu_properties->storage_format = 1;
npu_properties->storage_layout = 2;
npu_properties->storage_format = 3;
npu_properties->storage_dims = {1, 1, 1, 1, 16};
tensor.set_storage_properties(std::move(npu_properties));
EXPECT_TRUE(tensor.storage_properties_initialized());
auto get_npu_properties = tensor.storage_properties<NPUStorageProperties>();
CHECK_EQ(get_npu_properties.storage_format, 1);
CHECK_EQ(get_npu_properties.storage_layout, 2);
CHECK_EQ(get_npu_properties.storage_format, 3);
CHECK_EQ(get_npu_properties.storage_dims.size(), 5);
// test error type storage properties
#ifdef PADDLE_WITH_MKLDNN
......@@ -177,8 +179,8 @@ TEST(dense_tensor, storage_properties) {
auto cp_tensor = tensor;
auto get_cp_npu_properties =
cp_tensor.storage_properties<NPUStorageProperties>();
CHECK_EQ(get_cp_npu_properties.storage_format, 1);
CHECK_EQ(get_cp_npu_properties.storage_layout, 2);
CHECK_EQ(get_cp_npu_properties.storage_format, 3);
CHECK_EQ(get_cp_npu_properties.storage_dims.size(), 5);
}
} // namespace tests
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册