diff --git a/src/common/common.h b/src/common/common.h index c59e6b7932e73bd19b56d4dd081adff8689d5cf3..ed23b543b36d2b74a18046d241aeeb9b164cee15 100644 --- a/src/common/common.h +++ b/src/common/common.h @@ -28,4 +28,4 @@ inline double time_diff(Time t1, Time t2) { return counter.count() / 1000.0; } -} +} // namespace paddle_mobile diff --git a/src/framework/cl/cl_image.h b/src/framework/cl/cl_image.h index 5943ecc9c78c92086d734c19140c0a9bfb71c661..a144ccf35b5bf41b3ffbbc65a18b92271a16003c 100644 --- a/src/framework/cl/cl_image.h +++ b/src/framework/cl/cl_image.h @@ -118,7 +118,20 @@ class CLImage { cl_image_format cf = {.image_channel_order = CL_RGBA, .image_channel_data_type = CL_HALF_FLOAT}; // NCHW -> [W * (C+3)/4, H * N] - DLOG << tensor_dims_; + tensor_dims_ = dim; + if (tensor_data) { + tensor_data_ = tensor_data; + } else { + int numel = 1; + for (int i = 0; i < dim.size(); i++) { + numel *= dim[i]; + } + tensor_data_ = static_cast( + paddle_mobile::memory::Alloc(sizeof(float) * numel)); + for (int i = 0; i < numel; i++) { + tensor_data_[i] = 0; + } + } size_t N, C, H, W; if (tensor_dims_.size() == 4) { N = tensor_dims_[0]; diff --git a/src/framework/executor.cpp b/src/framework/executor.cpp index 27052de2fd820ddb9c220b3d8230982878620d02..274a6a1d82bc1a8b939226a01d74f7b1172c81cd 100644 --- a/src/framework/executor.cpp +++ b/src/framework/executor.cpp @@ -936,7 +936,7 @@ void Executor::InitMemory() { cl_image->SetTensorData(tensorInput, ddim); delete origin_data; - paddle_mobile::memory::Free(tensorInput); + // paddle_mobile::memory::Free(tensorInput); } else { if (var_desc->Type() == framework::VARTYPE_TYPE_LOD_TENSOR) { auto cl_image = var->template GetMutable(); diff --git a/src/framework/operator.cpp b/src/framework/operator.cpp index fa04ac2e464a2dfa9c79b8e338ca66f5b0d6978f..68ce52114cedd4267ef7fa40f9043bc4363bda9f 100644 --- a/src/framework/operator.cpp +++ b/src/framework/operator.cpp @@ -72,13 +72,16 @@ void OperatorBase::Run() { if (tensor) DLOG << type_ << " input- " << key << "=" << *tensor; } else { CLImage *cl_image = vari->template GetMutable(); - // cl_command_queue commandQueue = - // scope_->GetCLScpoe()->CommandQueue(); Tensor *tmp ; - // CLImageToTensor(cl_image,tmp,commandQueue); - // tmp->Resize(cl_image->dims()); + // cl_command_queue commandQueue = + // scope_->GetCLScpoe()->CommandQueue(); Tensor + // *tmp ; + // CLImageToTensor(cl_image,tmp,commandQueue); + // tmp->Resize(cl_image->dims()); + const float *input = cl_image->data(); if (cl_image) { - // DLOG<template GetMutable(); + if (tensor) + DLOG << type_ << " output- " << key << "=" << tensor->dims(); + } else { + CLImage *cl_image = vari->template GetMutable(); + // cl_command_queue commandQueue = + // scope_->GetCLScpoe()->CommandQueue(); Tensor *tmp ; + // CLImageToTensor(cl_image,tmp,commandQueue); + // tmp->Resize(cl_image->dims()); + if (cl_image) { + const float *output = cl_image->data(); + DLOG << type_ << " output- " << key << "=" << cl_image->dims(); + // if(output) + // DLOG<cl_helper_.KernelAt(0); cl_int status; auto output = param.Out(); - auto input = param.InputX(); - DLOG << " input: " << input; + const Tensor *input = param.InputX(); + const float *input_data = nullptr; + input_data = input->data(); - const float *input_data = input->data(); cl_mem cl_image = output->GetCLImage(); int height = output->dims()[2]; int width = output->dims()[3]; + DLOG << output->dims(); status = clSetKernelArg(kernel, 0, sizeof(cl_mem), &input_data); status = clSetKernelArg(kernel, 0, sizeof(cl_mem), &cl_image); status = clSetKernelArg(kernel, 0, sizeof(cl_mem), &width); diff --git a/test/net/test_googlenet.cpp b/test/net/test_googlenet.cpp index 9e826d3a747c5207f81baa5973d7da6aabc2103f..6e3465271bed8f158256b6458dc59f789ab2ed28 100644 --- a/test/net/test_googlenet.cpp +++ b/test/net/test_googlenet.cpp @@ -30,7 +30,8 @@ int main() { auto time1 = time(); if (paddle_mobile.Load(g_googlenet, optimize)) { auto time2 = paddle_mobile::time(); - std::cout << "load cost :" << paddle_mobile::time_diff(time1, time2) << "ms" << std::endl; + std::cout << "load cost :" << paddle_mobile::time_diff(time1, time2) << "ms" + << std::endl; std::vector input; std::vector dims{1, 3, 224, 224}; GetInput(g_test_image_1x3x224x224, &input, dims); diff --git a/test/net/test_mobilenet_GPU.cpp b/test/net/test_mobilenet_GPU.cpp index f65e1890f362e4c8e4ebeba9c5a59d79da1b2791..70983e2b1504fb078dce61a45c5c47a96201bc2d 100644 --- a/test/net/test_mobilenet_GPU.cpp +++ b/test/net/test_mobilenet_GPU.cpp @@ -26,7 +26,8 @@ int main() { auto isok = paddle_mobile.Load(g_mobilenet, false); if (isok) { auto time2 = paddle_mobile::time(); - std::cout << "load cost :" << paddle_mobile::time_diff(time1, time1) << "ms" << std::endl; + std::cout << "load cost :" << paddle_mobile::time_diff(time1, time1) << "ms" + << std::endl; std::vector input; std::vector dims{1, 3, 224, 224}; @@ -48,8 +49,8 @@ int main() { } DLOG << vec_result; auto time4 = paddle_mobile::time(); - std::cout << "predict cost :" << paddle_mobile::time_diff(time3, time4) / 10 << "ms" - << std::endl; + std::cout << "predict cost :" << paddle_mobile::time_diff(time3, time4) / 10 + << "ms" << std::endl; } std::cout << "如果结果Nan请查看: test/images/g_test_image_1x3x224x224_banana "