3 #include "DataTransfer.h" 6 #include "caffe2/core/logging.h" 7 #include "caffe2/core/timer.h" 9 #if CAFFE2_ANDROID && defined(__ARM_NEON__) 11 #include "../android/AndroidGLContext.h" 14 void arm_memcpy(
volatile unsigned char* dst,
volatile unsigned char* src,
int sz) {
21 " VLDM %[src]!,{d0-d7} \n" 22 " VSTM %[dst]!,{d0-d7} \n" 23 " SUBS %[sz],%[sz],#0x40 \n" 25 : [dst]
"+r"(dst), [src]
"+r"(src), [sz]
"+r"(sz)
27 :
"d0",
"d1",
"d2",
"d3",
"d4",
"d5",
"d6",
"d7",
"cc",
"memory");
31 const GLTexture::Type GLTexture::FP16 = {GL_RGBA16F, GL_RGBA, GL_HALF_FLOAT};
32 const GLTexture::Type GLTexture::UI8 = {GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE};
33 const GLTexture::Type GLTexture::FP16_COMPAT = {GL_RG32UI, GL_RG_INTEGER, GL_UNSIGNED_INT};
35 void GLTexture::map_read(std::function<
void(
const void* buffer,
40 const Type& type)> process)
const {
41 GLPBO* pbo = GLPBO::getContext();
42 pbo->mapTextureData(_textureId, _width, _height, _stride, _channels, _type, process);
45 void GLTexture::map_load(std::function<
void(
void* buffer,
50 const Type& type)> process)
const {
51 const int alignment = 32;
52 void* buffer =
nullptr;
53 size_t buffer_size = _width * _height * _channels * _type.dataSize();
56 buffer = (
void*)memalign(alignment, buffer_size);
58 posix_memalign((
void**)&buffer, alignment, buffer_size);
60 CAFFE_ENFORCE(buffer);
62 process(buffer, _width, _height, _width, _channels, _type);
67 void GLTexture::loadData(
const void* pixels)
const {
68 glBindTexture(GL_TEXTURE_2D, _textureId);
69 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, _width, _height, _type.format, _type.type, pixels);
70 glBindTexture(GL_TEXTURE_2D, 0);