Program Listing for File device_ptr.h

Return to documentation for file (thrust/device_ptr.h)

/*
 *  Copyright 2008-2013 NVIDIA Corporation
 *  Modifications Copyright© 2019 Advanced Micro Devices, Inc. All rights reserved.
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  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
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  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

#include <thrust/detail/config.h>
#include <thrust/memory.h>

namespace thrust
{

// forward declarations
template<typename T> class device_reference;

template<typename T>
  class device_ptr
    : public thrust::pointer<
               T,
               thrust::device_system_tag,
               thrust::device_reference<T>,
               thrust::device_ptr<T>
             >
{
  private:
    typedef thrust::pointer<
      T,
      thrust::device_system_tag,
      thrust::device_reference<T>,
      thrust::device_ptr<T>
    > super_t;

  public:
    __host__ __device__
    device_ptr() : super_t() {}

    template<typename OtherT>
    __host__ __device__
    explicit device_ptr(OtherT *ptr) : super_t(ptr) {}

    // Fixes HCC linkage error
    __host__ __device__
    explicit device_ptr(T *ptr) : super_t(ptr) {}

    template<typename OtherT>
    __host__ __device__
    device_ptr(const device_ptr<OtherT> &other) : super_t(other) {}

    template<typename OtherT>
    __host__ __device__
    device_ptr &operator=(const device_ptr<OtherT> &other)
    {
      super_t::operator=(other);
      return *this;
    }

// declare these members for the purpose of Doxygenating them
// they actually exist in a derived-from class
#if 0

    __host__ __device__
    T *get(void) const;
#endif // end doxygen-only members
}; // end device_ptr

// declare these methods for the purpose of Doxygenating them
// they actually are defined for a derived-from class
#if 0

template<typename T, typename charT, typename traits>
std::basic_ostream<charT, traits> &
operator<<(std::basic_ostream<charT, traits> &os, const device_ptr<T> &p);
#endif

template<typename T>
__host__ __device__
inline device_ptr<T> device_pointer_cast(T *ptr);

template<typename T>
__host__ __device__
inline device_ptr<T> device_pointer_cast(const device_ptr<T> &ptr);

} // end thrust

#include <thrust/detail/device_ptr.inl>
#include <thrust/detail/raw_pointer_cast.h>