2022-09-22 15:34:34 +08:00
|
|
|
#include "core/graph.h"
|
|
|
|
#include "core/kernel.h"
|
|
|
|
#include "core/perf_engine.h"
|
|
|
|
#include "core/runtime.h"
|
|
|
|
#include "cuda/cuda_runtime.h"
|
|
|
|
#include "cuda/cuda_utility.h"
|
|
|
|
#include "operators/conv.h"
|
|
|
|
#include "operators/matmul.h"
|
|
|
|
#include "test.h"
|
|
|
|
|
|
|
|
namespace infini {
|
|
|
|
|
|
|
|
TEST(PerfEngine, save_and_load) {
|
2023-03-27 21:28:49 +08:00
|
|
|
Runtime cpu = NativeCpuRuntimeObj::getInstance(); // CPUruntime is singleton
|
2022-09-22 15:34:34 +08:00
|
|
|
Graph gCpu = make_ref<GraphObj>(cpu);
|
|
|
|
Runtime cuda = make_ref<CudaRuntimeObj>();
|
2022-09-27 10:41:12 +08:00
|
|
|
{ // Conv
|
|
|
|
Graph gCuda = make_ref<GraphObj>(cuda);
|
|
|
|
|
|
|
|
// Copy input tensors from CPU to CUDA
|
|
|
|
Tensor i0Cuda = gCuda->addTensor({1, 3, 224, 224}, DataType::Float32);
|
|
|
|
Tensor w0Cuda = gCuda->addTensor({2, 3, 3, 3}, DataType::Float32);
|
|
|
|
// Build CUDA graph
|
|
|
|
auto conv =
|
|
|
|
gCuda->addOp<ConvObj>(i0Cuda, w0Cuda, nullptr, 1, 1, 1, 1, 1, 1);
|
|
|
|
gCuda->dataMalloc();
|
|
|
|
cuda->run(gCuda, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
{ // Matmul
|
|
|
|
Graph gCuda = make_ref<GraphObj>(cuda);
|
|
|
|
auto ACuda = gCuda->addTensor(Shape{1, 3, 5}, DataType::Float32);
|
|
|
|
auto BCuda = gCuda->addTensor(Shape{1, 5, 2}, DataType::Float32);
|
|
|
|
auto matmul = gCuda->addOp<MatmulObj>(ACuda, BCuda, nullptr);
|
|
|
|
gCuda->dataMalloc();
|
|
|
|
cuda->run(gCuda, true);
|
|
|
|
}
|
2022-09-22 15:34:34 +08:00
|
|
|
auto &perfEngine = PerfEngine::getInstance();
|
|
|
|
|
|
|
|
json j0 = perfEngine;
|
|
|
|
std::cout << "PerfEngine saveed:" << std::endl;
|
|
|
|
std::cout << j0 << std::endl;
|
|
|
|
perfEngine.savePerfEngineData("test.json");
|
|
|
|
perfEngine.loadPerfEngineData("test.json");
|
|
|
|
json j1 = perfEngine;
|
|
|
|
std::cout << "PerfEngine loaded:" << std::endl;
|
|
|
|
std::cout << j1 << std::endl;
|
|
|
|
EXPECT_TRUE(j0 == j1);
|
|
|
|
}
|
2022-10-15 16:29:28 +08:00
|
|
|
} // namespace infini
|