Skip to content

Commit

Permalink
Merge pull request ROCm#100 from weixingzhang/texture
Browse files Browse the repository at this point in the history
HIP Texture Support
  • Loading branch information
bensander authored Jul 27, 2017
2 parents bcdc668 + 9d5d4f9 commit 4f93b99
Show file tree
Hide file tree
Showing 15 changed files with 8,194 additions and 188 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ if(HIP_PLATFORM STREQUAL "hcc")
src/hip_module.cpp
src/hip_db.cpp
src/grid_launch.cpp
src/hip_texture.cpp
src/env.cpp)

set(SOURCE_FILES_DEVICE
Expand Down
7 changes: 6 additions & 1 deletion bin/hipify-perl
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ while (@ARGV) {

$ft{'mem'} += s/\bcudaMemcpy2D\b/hipMemcpy2D/g;
$ft{'mem'} += s/\bcudaMemcpy2DToArray\b/hipMemcpy2DToArray/g;
$ft{'mem'} += s/\bcudaMemcpyToArray\b/hipMemcpyToArray/g;

#--------
# Memory management:
Expand All @@ -302,6 +303,7 @@ while (@ARGV) {
$ft{'mem'} += s/\bcudaHostGetDevicePointer\b/hipHostGetDevicePointer/g;

$ft{'mem'} += s/\bcudaMallocArray\b/hipMallocArray/g;
$ft{'mem'} += s/\bcudaFreeArray\b/hipFreeArray/g;
$ft{'mem'} += s/\bcudaMallocPitch\b/hipMallocPitch/g;


Expand Down Expand Up @@ -511,11 +513,14 @@ while (@ARGV) {
$ft{'tex'} += s/\bcudaFilterModePoint\b/hipFilterModePoint/g;
$ft{'tex'} += s/\bcudaReadModeElementType\b/hipReadModeElementType/g;

$ft{'tex'} += s/\bcudaArray\b/hipArrary/g;
$ft{'tex'} += s/\bcudaArray\b/hipArray/g;
$ft{'tex'} += s/\bcudaCreateChannelDesc\b/hipCreateChannelDesc/g;
$ft{'tex'} += s/\bcudaBindTexture\b/hipBindTexture/g;
$ft{'tex'} += s/\bcudaBindTextureToArray\b/hipBindTextureToArray/g;
$ft{'tex'} += s/\bcudaUnbindTexture\b/hipUnbindTexture/g;
$ft{'tex'} += s/\bcudaChannelFormatKindFloat\b/hipChannelFormatKindFloat/g;
$ft{'tex'} += s/\bcudaAddressMode/hipAddressMode/g;
$ft{'tex'} += s/\bcudaFilterMode/hipFilterMode/g;
}


Expand Down
218 changes: 209 additions & 9 deletions include/hip/hcc_detail/driver_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,220 @@ THE SOFTWARE.

enum hipChannelFormatKind
{
hipChannelFormatKindSigned = 0,
hipChannelFormatKindUnsigned = 1,
hipChannelFormatKindFloat = 2,
hipChannelFormatKindNone = 3
hipChannelFormatKindSigned = 0,
hipChannelFormatKindUnsigned = 1,
hipChannelFormatKindFloat = 2,
hipChannelFormatKindNone = 3
};

struct hipChannelFormatDesc
{
int x;
int y;
int z;
int w;
enum hipChannelFormatKind f;
int x;
int y;
int z;
int w;
enum hipChannelFormatKind f;
};

struct hipArray {
void* data; //FIXME: generalize this
struct hipChannelFormatDesc desc;
unsigned int type;
unsigned int width;
unsigned int height;
unsigned int depth;
};

typedef struct hipArray* hipArray_t;

typedef const struct hipArray* hipArray_const_t;

// TODO: It needs to be modified since it was just copied from hipArray.
struct hipMipmappedArray {
void* data; //FIXME: generalize this
struct hipChannelFormatDesc desc;
unsigned int width;
unsigned int height;
unsigned int depth;
};

typedef struct hipMipmappedArray *hipMipmappedArray_t;

typedef const struct hipMipmappedArray *hipMipmappedArray_const_t;

/**
* hip resource types
*/
enum hipResourceType
{
hipResourceTypeArray = 0x00,
hipResourceTypeMipmappedArray = 0x01,
hipResourceTypeLinear = 0x02,
hipResourceTypePitch2D = 0x03
};

/**
* hip texture resource view formats
*/
enum hipResourceViewFormat
{
hipResViewFormatNone = 0x00,
hipResViewFormatUnsignedChar1 = 0x01,
hipResViewFormatUnsignedChar2 = 0x02,
hipResViewFormatUnsignedChar4 = 0x03,
hipResViewFormatSignedChar1 = 0x04,
hipResViewFormatSignedChar2 = 0x05,
hipResViewFormatSignedChar4 = 0x06,
hipResViewFormatUnsignedShort1 = 0x07,
hipResViewFormatUnsignedShort2 = 0x08,
hipResViewFormatUnsignedShort4 = 0x09,
hipResViewFormatSignedShort1 = 0x0a,
hipResViewFormatSignedShort2 = 0x0b,
hipResViewFormatSignedShort4 = 0x0c,
hipResViewFormatUnsignedInt1 = 0x0d,
hipResViewFormatUnsignedInt2 = 0x0e,
hipResViewFormatUnsignedInt4 = 0x0f,
hipResViewFormatSignedInt1 = 0x10,
hipResViewFormatSignedInt2 = 0x11,
hipResViewFormatSignedInt4 = 0x12,
hipResViewFormatHalf1 = 0x13,
hipResViewFormatHalf2 = 0x14,
hipResViewFormatHalf4 = 0x15,
hipResViewFormatFloat1 = 0x16,
hipResViewFormatFloat2 = 0x17,
hipResViewFormatFloat4 = 0x18,
hipResViewFormatUnsignedBlockCompressed1 = 0x19,
hipResViewFormatUnsignedBlockCompressed2 = 0x1a,
hipResViewFormatUnsignedBlockCompressed3 = 0x1b,
hipResViewFormatUnsignedBlockCompressed4 = 0x1c,
hipResViewFormatSignedBlockCompressed4 = 0x1d,
hipResViewFormatUnsignedBlockCompressed5 = 0x1e,
hipResViewFormatSignedBlockCompressed5 = 0x1f,
hipResViewFormatUnsignedBlockCompressed6H = 0x20,
hipResViewFormatSignedBlockCompressed6H = 0x21,
hipResViewFormatUnsignedBlockCompressed7 = 0x22
};

/**
* HIP resource descriptor
*/
struct hipResourceDesc {
enum hipResourceType resType;

union {
struct {
hipArray_t array;
} array;
struct {
hipMipmappedArray_t mipmap;
} mipmap;
struct {
void *devPtr;
struct hipChannelFormatDesc desc;
size_t sizeInBytes;
} linear;
struct {
void *devPtr;
struct hipChannelFormatDesc desc;
size_t width;
size_t height;
size_t pitchInBytes;
} pitch2D;
} res;
};

/**
* hip resource view descriptor
*/
struct hipResourceViewDesc
{
enum hipResourceViewFormat format;
size_t width;
size_t height;
size_t depth;
unsigned int firstMipmapLevel;
unsigned int lastMipmapLevel;
unsigned int firstLayer;
unsigned int lastLayer;
};

/**
* Memory copy types
*
*/
typedef enum hipMemcpyKind {
hipMemcpyHostToHost = 0, ///< Host-to-Host Copy
hipMemcpyHostToDevice = 1, ///< Host-to-Device Copy
hipMemcpyDeviceToHost = 2, ///< Device-to-Host Copy
hipMemcpyDeviceToDevice =3, ///< Device-to-Device Copy
hipMemcpyDefault = 4 ///< Runtime will automatically determine copy-kind based on virtual addresses.
} hipMemcpyKind;

struct hipPitchedPtr
{
void *ptr;
size_t pitch;
size_t xsize;
size_t ysize;
};

struct hipExtent {
size_t width; // Width in elements when referring to array memory, in bytes when referring to linear memory
size_t height;
size_t depth;
};

struct hipPos {
size_t x;
size_t y;
size_t z;
};

struct hipMemcpy3DParms {
hipArray_t srcArray;
struct hipPos srcPos;
struct hipPitchedPtr srcPtr;

hipArray_t dstArray;
struct hipPos dstPos;
struct hipPitchedPtr dstPtr;

struct hipExtent extent;
enum hipMemcpyKind kind;
};

static __inline__ struct hipPitchedPtr make_hipPitchedPtr(void *d, size_t p, size_t xsz, size_t ysz)
{
struct hipPitchedPtr s;

s.ptr = d;
s.pitch = p;
s.xsize = xsz;
s.ysize = ysz;

return s;
}

static __inline__ struct hipPos make_hipPos(size_t x, size_t y, size_t z)
{
struct hipPos p;

p.x = x;
p.y = y;
p.z = z;

return p;
}

static __inline__ struct hipExtent make_hipExtent(size_t w, size_t h, size_t d)
{
struct hipExtent e;

e.width = w;
e.height = h;
e.depth = d;

return e;
}

#endif
2 changes: 1 addition & 1 deletion include/hip/hcc_detail/hip_runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@ namespace hip_impl
extern int HIP_TRACE_API;

#ifdef __cplusplus
//#include <hip/hcc_detail/hip_texture.h>
#include <hip/hcc_detail/hip_ldg.h>
#endif
#include <hip/hcc_detail/host_defines.h>
#include <hip/hcc_detail/math_functions.h>
#include <hip/hcc_detail/device_functions.h>
#include <hip/hcc_detail/texture_functions.h>

// TODO-HCC remove old definitions ; ~1602 hcc supports __HCC_ACCELERATOR__ define.
#if defined (__KALMAR_ACCELERATOR__) && !defined (__HCC_ACCELERATOR__)
Expand Down
Loading

0 comments on commit 4f93b99

Please sign in to comment.