Commit 59df2998 authored by Fenglei Tian's avatar Fenglei Tian

fix code style, copyright, and clean unimplement functions

parent e08ee468
...@@ -34,7 +34,7 @@ runtime::gpu::GPU_CallFrame::GPU_CallFrame(std::shared_ptr<GPU_ExternalFunction> ...@@ -34,7 +34,7 @@ runtime::gpu::GPU_CallFrame::GPU_CallFrame(std::shared_ptr<GPU_ExternalFunction>
{ {
//Create context use driver API and make it current, the runtime call will pickup the context //Create context use driver API and make it current, the runtime call will pickup the context
//http://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#interoperability-between-runtime-and-driver-apis //http://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#interoperability-between-runtime-and-driver-apis
ngraph::runtime::gpu::Cuda_context_manager::Instance(); ngraph::runtime::gpu::CudaContextManager::Instance();
cublasStatus_t cublasStatus = cublasCreate(&m_cublas_handle); cublasStatus_t cublasStatus = cublasCreate(&m_cublas_handle);
if (cublasStatus != CUBLAS_STATUS_SUCCESS) if (cublasStatus != CUBLAS_STATUS_SUCCESS)
{ {
...@@ -46,7 +46,7 @@ runtime::gpu::GPU_CallFrame::GPU_CallFrame(std::shared_ptr<GPU_ExternalFunction> ...@@ -46,7 +46,7 @@ runtime::gpu::GPU_CallFrame::GPU_CallFrame(std::shared_ptr<GPU_ExternalFunction>
throw runtime_error("cuDnn create handle failed"); throw runtime_error("cuDnn create handle failed");
} }
// Pass scalars as reference on the Host // Pass scalars as reference on the Device
cublasSetPointerMode(m_cublas_handle, CUBLAS_POINTER_MODE_HOST); cublasSetPointerMode(m_cublas_handle, CUBLAS_POINTER_MODE_HOST);
} }
...@@ -60,7 +60,7 @@ void runtime::gpu::GPU_CallFrame::tensor_call( ...@@ -60,7 +60,7 @@ void runtime::gpu::GPU_CallFrame::tensor_call(
const std::vector<std::shared_ptr<ngraph::runtime::TensorView>>& input_tvs, const std::vector<std::shared_ptr<ngraph::runtime::TensorView>>& input_tvs,
const std::vector<std::shared_ptr<ngraph::runtime::TensorView>>& output_tvs) const std::vector<std::shared_ptr<ngraph::runtime::TensorView>>& output_tvs)
{ {
// Host tensors //Device tensors
vector<void*> inputs; vector<void*> inputs;
vector<void*> outputs; vector<void*> outputs;
......
...@@ -27,33 +27,33 @@ namespace ngraph ...@@ -27,33 +27,33 @@ namespace ngraph
{ {
namespace gpu namespace gpu
{ {
class Cuda_context_manager class CudaContextManager
{ {
public: public:
static Cuda_context_manager& Instance() static CudaContextManager& Instance()
{ {
static Cuda_context_manager manager; static CudaContextManager manager;
return manager; return manager;
} }
Cuda_context_manager(Cuda_context_manager const&) = delete; CudaContextManager(CudaContextManager const&) = delete;
Cuda_context_manager(Cuda_context_manager&&) = delete; CudaContextManager(CudaContextManager&&) = delete;
Cuda_context_manager& operator=(Cuda_context_manager const&) = delete; CudaContextManager& operator=(CudaContextManager const&) = delete;
Cuda_context_manager& operator=(Cuda_context_manager&&) = delete; CudaContextManager& operator=(CudaContextManager&&) = delete;
std::shared_ptr<CUcontext> GetContext() { return context_ptr; } std::shared_ptr<CUcontext> GetContext() { return context_ptr; }
protected: protected:
Cuda_context_manager() CudaContextManager()
{ {
CUDA_SAFE_CALL(cuInit(0)); CUDA_SAFE_CALL(cuInit(0));
CUDA_SAFE_CALL(cuDeviceGet(&cuDevice, 0)); CUDA_SAFE_CALL(cuDeviceGet(&m_device, 0));
CUDA_SAFE_CALL(cuCtxCreate(&context, 0, cuDevice)); CUDA_SAFE_CALL(cuCtxCreate(&m_context, 0, m_device));
context_ptr = std::make_shared<CUcontext>(context); m_context_ptr = std::make_shared<CUcontext>(m_context);
} }
~Cuda_context_manager() {} ~CudaContextManager() {}
CUdevice cuDevice; CUdevice m_device;
CUcontext context; CUcontext m_context;
std::shared_ptr<CUcontext> context_ptr; std::shared_ptr<CUcontext> m_context_ptr;
}; };
} }
} }
......
...@@ -27,7 +27,7 @@ namespace ngraph ...@@ -27,7 +27,7 @@ namespace ngraph
{ {
namespace gpu namespace gpu
{ {
class Cuda_function_builder class CudaFunctionBuilder
{ {
public: public:
static std::shared_ptr<CUfunction> Get(const std::string& name, static std::shared_ptr<CUfunction> Get(const std::string& name,
...@@ -43,23 +43,17 @@ namespace ngraph ...@@ -43,23 +43,17 @@ namespace ngraph
NULL, // headers NULL, // headers
NULL)); // includeNames NULL)); // includeNames
nvrtcResult compileResult = nvrtcResult compile_result =
nvrtcCompileProgram(prog, number_of_options, options); nvrtcCompileProgram(prog, number_of_options, options);
if (compileResult != NVRTC_SUCCESS) if (compile_result != NVRTC_SUCCESS)
{ {
// size_t logSize;
// NVRTC_SAFE_CALL(nvrtcGetProgramLogSize(prog, &logSize));
// char *log = new char[logSize];
// NVRTC_SAFE_CALL(nvrtcGetProgramLog(prog, log));
// std::cout << log << '\n';
// delete[] log;
throw std::runtime_error("compile error: \n" + kernel + "\n options"); throw std::runtime_error("compile error: \n" + kernel + "\n options");
} }
size_t ptxSize; size_t ptx_size;
NVRTC_SAFE_CALL(nvrtcGetPTXSize(prog, &ptxSize)); NVRTC_SAFE_CALL(nvrtcGetPTXSize(prog, &ptx_size));
char* ptx = new char[ptxSize]; char* ptx = new char[ptx_size];
NVRTC_SAFE_CALL(nvrtcGetPTX( NVRTC_SAFE_CALL(nvrtcGetPTX(
prog, prog,
ptx)); // Load the generated PTX and get a handle to the parent kernel. ptx)); // Load the generated PTX and get a handle to the parent kernel.
......
...@@ -27,29 +27,29 @@ namespace ngraph ...@@ -27,29 +27,29 @@ namespace ngraph
{ {
namespace gpu namespace gpu
{ {
class Cuda_function_pool class CudaFunctionPool
{ {
public: public:
static Cuda_function_pool& Instance() static CudaFunctionPool& Instance()
{ {
static Cuda_function_pool pool; static CudaFunctionPool pool;
return pool; return pool;
} }
Cuda_function_pool(Cuda_function_pool const&) = delete; CudaFunctionPool(CudaFunctionPool const&) = delete;
Cuda_function_pool(Cuda_function_pool&&) = delete; CudaFunctionPool(CudaFunctionPool&&) = delete;
Cuda_function_pool& operator=(Cuda_function_pool const&) = delete; CudaFunctionPool& operator=(CudaFunctionPool const&) = delete;
Cuda_function_pool& operator=(Cuda_function_pool&&) = delete; CudaFunctionPool& operator=(CudaFunctionPool&&) = delete;
void Set(std::string& name, std::shared_ptr<CUfunction> function) void Set(std::string& name, std::shared_ptr<CUfunction> function)
{ {
CUfunction_map.insert({name, function}); m_function_map.insert({name, function});
} }
std::shared_ptr<CUfunction> Get(std::string& name) std::shared_ptr<CUfunction> Get(std::string& name)
{ {
auto it = CUfunction_map.find(name); auto it = m_function_map.find(name);
if (it != CUfunction_map.end()) if (it != m_function_map.end())
{ {
return (*it).second; return (*it).second;
} }
...@@ -57,9 +57,9 @@ namespace ngraph ...@@ -57,9 +57,9 @@ namespace ngraph
} }
protected: protected:
Cuda_function_pool() {} CudaFunctionPool() {}
~Cuda_function_pool() {} ~CudaFunctionPool() {}
std::unordered_map<std::string, std::shared_ptr<CUfunction>> CUfunction_map; std::unordered_map<std::string, std::shared_ptr<CUfunction>> m_function_map;
}; };
} }
} }
......
...@@ -43,7 +43,7 @@ namespace ngraph ...@@ -43,7 +43,7 @@ namespace ngraph
std::string kernel; std::string kernel;
Cuda_kernel_builder::Get_1_element_op(name, "float", "fabsf", kernel); Cuda_kernel_builder::Get_1_element_op(name, "float", "fabsf", kernel);
Cuda_function_pool::Instance().Set( Cuda_function_pool::Instance().Set(
name, Cuda_function_builder::Get("cuda_" + name, kernel, 2, opts)); name, CudaFunctionBuilder::Get("cuda_" + name, kernel, 2, opts));
} }
//convert runtime ptr to driver api ptr //convert runtime ptr to driver api ptr
...@@ -66,74 +66,6 @@ namespace ngraph ...@@ -66,74 +66,6 @@ namespace ngraph
0)); // arguments 0)); // arguments
CUDA_SAFE_CALL(cuCtxSynchronize()); // Retrieve and print output. CUDA_SAFE_CALL(cuCtxSynchronize()); // Retrieve and print output.
} }
void emit_broadcast(codegen::CodeWriter& writer,
const std::string& element_type,
const std::string& arg0, // replacement context
const std::string& out,
const Shape& arg0_shape,
const Shape& out_shape,
const AxisSet& broadcast_axes)
{
}
//
// For the reference kernel this is gpud on, see ngraph/runtime/kernel/concat.hpp.
//
void emit_concat(codegen::CodeWriter& writer,
const std::string& element_type,
const std::vector<std::string>& args,
const std::string& out,
const std::vector<Shape>& in_shapes,
const Shape& out_shape,
size_t concatenation_axis)
{
}
void emit_replace_slice(codegen::CodeWriter& writer,
const std::string& element_type,
const std::string& arg0, // replacement context
const std::string& arg1, // replacement value
const std::string& out,
const Shape& arg1_shape,
const Shape& out_shape,
const Coordinate& lower_bounds,
const Coordinate& upper_bounds,
const Strides& strides)
{
}
void emit_slice(codegen::CodeWriter& writer,
const std::string& element_type,
const std::string& arg0, // replacement context
const std::string& out,
const Shape& arg0_shape,
const Shape& out_shape,
const Coordinate& lower_bounds,
const Coordinate& upper_bounds,
const Strides& strides)
{
}
void emit_reshape(codegen::CodeWriter& writer,
const std::string& element_type,
const std::string& arg0, // replacement context
const std::string& out,
const Shape& arg0_shape,
const Shape& out_shape,
const AxisVector& arg0_axis_order)
{
}
void emit_sum(codegen::CodeWriter& writer,
const std::string& element_type,
const std::string& arg0, // replacement context
const std::string& out,
const Shape& arg0_shape,
const Shape& out_shape,
const AxisSet& reduction_axes)
{
}
} }
} }
} }
......
// ---------------------------------------------------------------------------- /*******************************************************************************
// Copyright 2017 Nervana Systems Inc. * Copyright 2017-2018 Intel Corporation
// Licensed under the Apache License, Version 2.0 (the "License"); *
// you may not use this file except in compliance with the License. * Licensed under the Apache License, Version 2.0 (the "License");
// You may obtain a copy of the License at * you may not use this file except in compliance with the License.
// * You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0 *
// * http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software *
// distributed under the License is distributed on an "AS IS" BASIS, * Unless required by applicable law or agreed to in writing, software
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// ---------------------------------------------------------------------------- * See the License for the specific language governing permissions and
* limitations under the License.
*******************************************************************************/
#pragma once #pragma once
...@@ -28,55 +30,6 @@ namespace ngraph ...@@ -28,55 +30,6 @@ namespace ngraph
namespace kernel namespace kernel
{ {
void emit_abs(void* in, void* out, size_t count); void emit_abs(void* in, void* out, size_t count);
void emit_broadcast(codegen::CodeWriter& writer,
const std::string& element_type,
const std::string& arg0, // replacement context
const std::string& out,
const Shape& arg0_shape,
const Shape& out_shape,
const AxisSet& broadcast_axes);
void emit_concat(codegen::CodeWriter& writer,
const std::string& element_type,
const std::vector<std::string>& args,
const std::string& out,
const std::vector<Shape>& in_shapes,
const Shape& out_shape,
const size_t concatenation_axis);
void emit_replace_slice(codegen::CodeWriter& writer,
const std::string& element_type,
const std::string& arg0, // replacement context
const std::string& arg1, // replacement value
const std::string& out,
const Shape& arg1_shape,
const Shape& out_shape,
const Coordinate& lower_bounds,
const Coordinate& upper_bounds,
const Strides& strides);
void emit_slice(codegen::CodeWriter& writer,
const std::string& element_type,
const std::string& arg0, // replacement context
const std::string& out,
const Shape& arg0_shape,
const Shape& out_shape,
const Coordinate& lower_bounds,
const Coordinate& upper_bounds,
const Strides& strides);
void emit_reshape(codegen::CodeWriter& writer,
const std::string& element_type,
const std::string& arg0, // replacement context
const std::string& out,
const Shape& arg0_shape,
const Shape& out_shape,
const AxisVector& arg0_axis_order);
void emit_sum(codegen::CodeWriter& writer,
const std::string& element_type,
const std::string& arg0, // replacement context
const std::string& out,
const Shape& arg0_shape,
const Shape& out_shape,
const AxisSet& reduction_axes);
} }
} }
} }
......
...@@ -22,6 +22,8 @@ ...@@ -22,6 +22,8 @@
#include <cudnn_v7.h> #include <cudnn_v7.h>
#include <nvrtc.h> #include <nvrtc.h>
//why use "do...while.."
//https://stackoverflow.com/questions/154136/why-use-apparently-meaningless-do-while-and-if-else-statements-in-macros
#define NVRTC_SAFE_CALL(x) \ #define NVRTC_SAFE_CALL(x) \
do \ do \
{ \ { \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment