github.com/rohankumardubey/aresdb@v0.0.2-0.20190517170215-e54e3ca06b9c/query/memory.cu (about)

     1  //  Copyright (c) 2017-2018 Uber Technologies, Inc.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  #ifndef QUERY_MEMORY_HPP
    16  #define QUERY_MEMORY_HPP
    17  
    18  #include "query/memory.hpp"
    19  #include <cuda_runtime.h>
    20  #include <cstdlib>
    21  #include <cstring>
    22  #include <string>
    23  #include "memutils/memory.h"
    24  #include "query/utils.hpp"
    25  
    26  // MemoryError represents a memory error.
    27  class MemoryError : public AlgorithmError{
    28   public:
    29    explicit MemoryError(const std::string &message) : AlgorithmError(message) {
    30    }
    31  };
    32  
    33  void checkMemoryError(CGoCallResHandle res) {
    34    if (res.pStrErr != nullptr) {
    35      throw MemoryError(res.pStrErr);
    36    }
    37  }
    38  
    39  namespace ares {
    40  void deviceMalloc(void **devPtr, size_t size) {
    41    checkMemoryError(::deviceMalloc(devPtr, size));
    42  }
    43  
    44  void deviceFree(void *devPtr) {
    45    checkMemoryError(::deviceFree(devPtr));
    46  }
    47  
    48  void deviceMemset(void *devPtr, int value, size_t count) {
    49    checkMemoryError(::deviceMemset(devPtr, value, count));
    50  }
    51  
    52  void asyncCopyHostToDevice(void* dst, const void* src, size_t count,
    53      cudaStream_t stream) {
    54    checkMemoryError(::asyncCopyHostToDevice(dst, src, count, stream));
    55  }
    56  
    57  }  // namespace ares
    58  #endif  // QUERY_MEMORY_HPP