mxnet
mxrtc.h
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  */
19 
25 #ifndef MXNET_MXRTC_H_
26 #define MXNET_MXRTC_H_
27 #include "./base.h"
28 #if ((MXNET_USE_CUDA) && (MXNET_USE_NVRTC))
29 #include <nvrtc.h>
30 #include <cuda.h>
31 
32 #include <vector>
33 #include <string>
34 #include <memory>
35 #include <utility>
36 #include <unordered_map>
37 #include "./ndarray.h"
38 
39 namespace mxnet {
40 
44 class MXRtc {
45  public:
56  MXRtc(const std::string& name,
57  std::vector<std::pair<std::string, NDArray> > const& input,
58  std::vector<std::pair<std::string, NDArray> > const& output,
59  const std::string& kernel);
71  void push(std::vector<NDArray> const& input,
72  std::vector<NDArray> const& output,
73  unsigned int grid_dim_X,
74  unsigned int grid_dim_Y,
75  unsigned int grid_dim_Z,
76  unsigned int block_dim_X,
77  unsigned int block_dim_Y,
78  unsigned int block_dim_Z);
79 
80  private:
81  static const char str_type[];
82  static std::unordered_map<std::string, char*> kernel_registry;
83 
84  std::string name_;
85  index_t num_input_, num_output_;
86  std::string code_;
87  char* ptx_;
88  std::unordered_map<int, CUmodule> module_;
89  std::unordered_map<int, CUfunction> func_;
90 
94  std::string decorate(const std::string& name,
95  std::vector<std::pair<std::string, NDArray> > const& input,
96  std::vector<std::pair<std::string, NDArray> > const& output,
97  const std::string kernel);
101  char* compile(const std::string& name, const std::string& code);
102 };
103 
104 } // namespace mxnet
105 
106 #endif // MXNET_USE_CUDA && MXNET_USE_NVRTC
107 #endif // MXNET_MXRTC_H_
namespace of mxnet
Definition: base.h:126
mshadow::index_t index_t
index type usually use unsigned
Definition: base.h:132