forked from ComputationalRadiationPhysics/haseongpu
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* ConstHybridVector provices the method free to manually free device memory * A better solution would be a reference counting implementation, but there is no out of the box solution like boost::shared_ptr * Leaves ComputationalRadiationPhysics#62 still open (smart pointers necessary) * closes: ComputationalRadiationPhysics#18
- Loading branch information
Erik Zenker
committed
Jul 2, 2015
1 parent
d402a16
commit df9e51f
Showing
9 changed files
with
112 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#pragma once | ||
|
||
// STL | ||
#include <vector> /* std::vector */ | ||
|
||
#include <cuda_utils.hpp> /* copyToDevice */ | ||
|
||
|
||
/** | ||
* @brief Vector on host and array on device | ||
* with transparent access. Access is | ||
* triggered based on a compiler macro. | ||
* | ||
**/ | ||
template<class T> | ||
class ConstHybridVector { | ||
public: | ||
|
||
ConstHybridVector(std::vector<T> &srcV) : | ||
hostV(srcV), | ||
deviceV(copyToDevice(srcV)){ | ||
|
||
} | ||
|
||
__forceinline__ __host__ __device__ T at(int i) const{ | ||
#ifdef __CUDA_ARCH__ | ||
return deviceV[i]; | ||
#else | ||
return hostV.at(i); | ||
#endif | ||
} | ||
|
||
__forceinline__ __host__ __device__ const T operator[] (int i) const { | ||
#ifdef __CUDA_ARCH__ | ||
return deviceV[i]; | ||
#else | ||
return hostV[i]; | ||
#endif | ||
} | ||
|
||
__host__ operator T*(){ | ||
return &(hostV.at(0)); | ||
} | ||
|
||
__host__ T* toArray() const{ | ||
std::vector<T> copyV = hostV; | ||
return &(copyV.at(0)); | ||
} | ||
|
||
__host__ std::vector<T> toVector() const{ | ||
return hostV; | ||
} | ||
|
||
__host__ void free() { | ||
cudaFree(deviceV); | ||
} | ||
|
||
private: | ||
T *deviceV; | ||
std::vector<T> hostV; | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters