开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
捐赠
捐赠前请先登录
扫描微信二维码支付
取消
支付完成
支付提示
将跳转至支付宝完成支付
确定
取消
1 Star 0 Fork 3

xiongying/Halide

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
main
分支 (1093)
标签 (17)
main
xtensa-codegen
vksnk/dma-limit-channels
rootjalex/trs-codegen-cross
abadams/fix_7374
abadams/remove_hack_from_gpu_only_aottest
srj/gpu-cache
srj/generator_aot_gpu_multi_context_threaded
srj/xtensa-merge
abadams/vector_scan
abadams/fix_7365
darya-ver/ir-viz
vulkan-phase2-runtime
srj/param-map-deprecation
srj/rt-return-types
srj/main-vs2022
release/15.x
srj/param-map
abadams/ir_builder_unique_ptr
vksnk/restrict
v14.0.0
v13.0.4
v13.0.3
v13.0.2
v13.0.1
v13.0.0
v12.0.1
v12.0.0
v11.0.1
v11.0.0
v10.0.1
v10.0.0
release_2019_08_27
release_8.0.0
v8.0.0
release_2018_02_15
release_2013_11_11
main
分支 (1093)
标签 (17)
main
xtensa-codegen
vksnk/dma-limit-channels
rootjalex/trs-codegen-cross
abadams/fix_7374
abadams/remove_hack_from_gpu_only_aottest
srj/gpu-cache
srj/generator_aot_gpu_multi_context_threaded
srj/xtensa-merge
abadams/vector_scan
abadams/fix_7365
darya-ver/ir-viz
vulkan-phase2-runtime
srj/param-map-deprecation
srj/rt-return-types
srj/main-vs2022
release/15.x
srj/param-map
abadams/ir_builder_unique_ptr
vksnk/restrict
v14.0.0
v13.0.4
v13.0.3
v13.0.2
v13.0.1
v13.0.0
v12.0.1
v12.0.0
v11.0.1
v11.0.0
v10.0.1
v10.0.0
release_2019_08_27
release_8.0.0
v8.0.0
release_2018_02_15
release_2013_11_11
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
main
分支 (1093)
标签 (17)
main
xtensa-codegen
vksnk/dma-limit-channels
rootjalex/trs-codegen-cross
abadams/fix_7374
abadams/remove_hack_from_gpu_only_aottest
srj/gpu-cache
srj/generator_aot_gpu_multi_context_threaded
srj/xtensa-merge
abadams/vector_scan
abadams/fix_7365
darya-ver/ir-viz
vulkan-phase2-runtime
srj/param-map-deprecation
srj/rt-return-types
srj/main-vs2022
release/15.x
srj/param-map
abadams/ir_builder_unique_ptr
vksnk/restrict
v14.0.0
v13.0.4
v13.0.3
v13.0.2
v13.0.1
v13.0.0
v12.0.1
v12.0.0
v11.0.1
v11.0.0
v10.0.1
v10.0.0
release_2019_08_27
release_8.0.0
v8.0.0
release_2018_02_15
release_2013_11_11
Halide
/
src
/
runtime
/
write_debug_image.cpp
Halide
/
src
/
runtime
/
write_debug_image.cpp
write_debug_image.cpp 12.30 KB
一键复制 编辑 原始数据 按行查看 历史
Steven Johnson 提交于 2022年11月19日 01:08 +08:00 . Add fopen() bottleneck to runtime (#7171)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382
#include "HalideRuntime.h"
// We support three formats, tiff, mat, and tmp.
//
// All formats support arbitrary types, and are easy to write in a
// small amount of code.
//
// TIFF:
// - 2/3-D only
// - Readable by the most tools
// mat:
// - Arbitrary dimensionality, type
// - Readable by matlab, ImageStack, and many other tools
// tmp:
// - Dirt simple, easy to roll your own parser
// - Readable by ImageStack only
// - Will probably be deprecated in favor of .mat soon
//
// It would be nice to use a format that web browsers read and display
// directly, but those formats don't tend to satisfy the above goals.
namespace Halide {
namespace Runtime {
namespace Internal {
// Mappings from the type_code passed in to the type codes of the
// formats. See "type_code" in DebugToFile.cpp
// TIFF sample type values are:
// 1 => Unsigned int
// 2 => Signed int
// 3 => Floating-point
WEAK int16_t pixel_type_to_tiff_sample_type[] = {
// float, double, uint8, int8, ... uint64, int64
3, 3, 1, 2, 1, 2, 1, 2, 1, 2};
// See the .mat level 5 documentation for matlab class codes.
WEAK uint8_t pixel_type_to_matlab_class_code[] = {
7, 6, 9, 8, 11, 10, 13, 12, 15, 14};
WEAK uint8_t pixel_type_to_matlab_type_code[] = {
7, 9, 2, 1, 4, 3, 6, 5, 13, 12};
#pragma pack(push)
#pragma pack(2)
struct tiff_tag {
uint16_t tag_code;
int16_t type_code;
int32_t count;
union {
int8_t i8;
int16_t i16;
int32_t i32;
} value;
ALWAYS_INLINE void assign16(uint16_t tag_code, int32_t count, int16_t value) {
this->tag_code = tag_code;
this->type_code = 3;
this->count = count;
this->value.i16 = value;
}
ALWAYS_INLINE void assign32(uint16_t tag_code, int32_t count, int32_t value) {
this->tag_code = tag_code;
this->type_code = 4;
this->count = count;
this->value.i32 = value;
}
ALWAYS_INLINE void assign32(uint16_t tag_code, int16_t type_code, int32_t count, int32_t value) {
this->tag_code = tag_code;
this->type_code = type_code;
this->count = count;
this->value.i32 = value;
}
};
struct halide_tiff_header {
int16_t byte_order_marker;
int16_t version;
int32_t ifd0_offset;
int16_t entry_count;
tiff_tag entries[15];
int32_t ifd0_end;
int32_t width_resolution[2];
int32_t height_resolution[2];
};
#pragma pack(pop)
WEAK bool ends_with(const char *filename, const char *suffix) {
const char *f = filename, *s = suffix;
while (*f) {
f++;
}
while (*s) {
s++;
}
while (s != suffix && f != filename) {
if (*f != *s) {
return false;
}
f--;
s--;
}
return *f == *s;
}
struct ScopedFile {
void *f;
ALWAYS_INLINE ScopedFile(const char *filename, const char *mode) {
f = halide_fopen(filename, mode);
}
ALWAYS_INLINE ~ScopedFile() {
if (f) {
fclose(f);
}
}
ALWAYS_INLINE bool write(const void *ptr, size_t bytes) {
return f ? fwrite(ptr, bytes, 1, f) > 0 : false;
}
ALWAYS_INLINE bool open() const {
return f != nullptr;
}
};
} // namespace Internal
} // namespace Runtime
} // namespace Halide
WEAK extern "C" int32_t halide_debug_to_file(void *user_context, const char *filename,
int32_t type_code, struct halide_buffer_t *buf) {
if (buf->is_bounds_query()) {
halide_error(user_context, "Bounds query buffer passed to halide_debug_to_file");
return -1;
}
if (buf->dimensions > 4) {
halide_error(user_context, "Can't debug_to_file a Func with more than four dimensions\n");
return -1;
}
int result = halide_copy_to_host(user_context, buf);
if (result != 0) {
return result;
}
ScopedFile f(filename, "wb");
if (!f.open()) {
return -2;
}
size_t elts = 1;
halide_dimension_t shape[4];
for (int i = 0; i < buf->dimensions && i < 4; i++) {
shape[i] = buf->dim[i];
elts *= shape[i].extent;
}
for (int i = buf->dimensions; i < 4; i++) {
shape[i].min = 0;
shape[i].extent = 1;
shape[i].stride = 0;
}
int32_t bytes_per_element = buf->type.bytes();
uint32_t final_padding_bytes = 0;
if (ends_with(filename, ".tiff") || ends_with(filename, ".tif")) {
int32_t channels;
int32_t width = shape[0].extent;
int32_t height = shape[1].extent;
int32_t depth;
if ((shape[3].extent == 0 || shape[3].extent == 1) && (shape[2].extent < 5)) {
channels = shape[2].extent;
depth = 1;
} else {
channels = shape[3].extent;
depth = shape[2].extent;
}
struct halide_tiff_header header;
int32_t MMII = 0x4d4d4949;
// Select the appropriate two bytes signaling byte order automatically
const char *c = (const char *)&MMII;
header.byte_order_marker = (c[0] << 8) | c[1];
header.version = 42;
header.ifd0_offset = __builtin_offsetof(halide_tiff_header, entry_count);
header.entry_count = sizeof(header.entries) / sizeof(header.entries[0]);
tiff_tag *tag = &header.entries[0];
tag++->assign32(256, 1, width); // Image width
tag++->assign32(257, 1, height); // Image height
tag++->assign16(258, 1, int16_t(bytes_per_element * 8)); // Bits per sample
tag++->assign16(259, 1, 1); // Compression -- none
tag++->assign16(262, 1, channels >= 3 ? 2 : 1); // PhotometricInterpretation -- black is zero or RGB
tag++->assign32(273, channels, sizeof(header)); // Rows per strip
tag++->assign16(277, 1, int16_t(channels)); // Samples per pixel
tag++->assign32(278, 1, shape[1].extent); // Rows per strip
tag++->assign32(279, channels,
(channels == 1) ?
elts * bytes_per_element :
sizeof(header) +
channels * sizeof(int32_t)); // strip byte counts, bug if 32-bit truncation
tag++->assign32(282, 5, 1,
__builtin_offsetof(halide_tiff_header, width_resolution)); // Width resolution
tag++->assign32(283, 5, 1,
__builtin_offsetof(halide_tiff_header, height_resolution)); // Height resolution
tag++->assign16(284, 1, 2); // Planar configuration -- planar
tag++->assign16(296, 1, 1); // Resolution Unit -- none
tag++->assign16(339, 1,
pixel_type_to_tiff_sample_type[type_code]); // Sample type
tag++->assign32(32997, 1, depth); // Image depth
header.ifd0_end = 0;
header.width_resolution[0] = 1;
header.width_resolution[1] = 1;
header.height_resolution[0] = 1;
header.height_resolution[1] = 1;
if (!f.write((void *)(&header), sizeof(header))) {
return -3;
}
if (channels > 1) {
int32_t offset = sizeof(header) + channels * sizeof(int32_t) * 2;
for (int32_t i = 0; i < channels; i++) {
if (!f.write((void *)(&offset), 4)) {
return -4;
}
offset += shape[0].extent * shape[1].extent * depth * bytes_per_element;
}
int32_t count = shape[0].extent * shape[1].extent * depth * bytes_per_element;
for (int32_t i = 0; i < channels; i++) {
if (!f.write((void *)(&count), 4)) {
return -5;
}
}
}
} else if (ends_with(filename, ".mat")) {
// Construct a name for the array from the filename
const char *end = filename;
while (*end) {
end++;
}
while (*end != '.') {
end--;
}
const char *start = end;
while (start != filename && start[-1] != '/') {
start--;
}
uint32_t name_size = (uint32_t)(end - start);
char array_name[256];
char *dst = array_name;
while (start != end) {
*dst++ = *start++;
}
while (dst < array_name + sizeof(array_name)) {
*dst++ = 0;
}
uint32_t padded_name_size = (name_size + 7) & ~7;
char header[129] =
"MATLAB 5.0 MAT-file, produced by Halide "
" 000円001円IM";
f.write(header, 128);
size_t payload_bytes = buf->size_in_bytes();
final_padding_bytes = 7 - ((payload_bytes - 1) & 7);
// level 5 .mat files have a size limit. (Padding itself should never cause the overflow.
// Code written this way for safety.)
if (((uint64_t)payload_bytes + final_padding_bytes) >> 32) {
halide_error(user_context, "Can't debug_to_file to a .mat file greater than 4GB\n");
return -6;
}
int dims = buf->dimensions;
// .mat files require at least two dimensions
if (dims < 2) {
dims = 2;
}
int padded_dimensions = (dims + 1) & ~1;
uint32_t tags[] = {
// This is a matrix
14, 40 + padded_dimensions * 4 + padded_name_size + (uint32_t)payload_bytes + final_padding_bytes,
// The element type
6, 8, pixel_type_to_matlab_class_code[type_code], 1,
// The shape
5, (uint32_t)(dims * 4)};
if (!f.write(&tags, sizeof(tags))) {
return -7;
}
int extents[] = {shape[0].extent, shape[1].extent, shape[2].extent, shape[3].extent};
if (!f.write(&extents, padded_dimensions * 4)) {
return -8;
}
// The name
uint32_t name_header[2] = {1, name_size};
if (!f.write(&name_header, sizeof(name_header))) {
return -9;
}
if (!f.write(array_name, padded_name_size)) {
return -10;
}
// Payload header
uint32_t payload_header[2] = {
pixel_type_to_matlab_type_code[type_code], (uint32_t)payload_bytes};
if (!f.write(payload_header, sizeof(payload_header))) {
return -11;
}
} else {
int32_t header[] = {shape[0].extent,
shape[1].extent,
shape[2].extent,
shape[3].extent,
type_code};
if (!f.write((void *)(&header[0]), sizeof(header))) {
return -12;
}
}
// Reorder the data according to the strides.
const int TEMP_SIZE = 4 * 1024;
uint8_t temp[TEMP_SIZE];
int max_elts = TEMP_SIZE / bytes_per_element;
int counter = 0;
for (int32_t dim3 = shape[3].min; dim3 < shape[3].extent + shape[3].min; ++dim3) {
for (int32_t dim2 = shape[2].min; dim2 < shape[2].extent + shape[2].min; ++dim2) {
for (int32_t dim1 = shape[1].min; dim1 < shape[1].extent + shape[1].min; ++dim1) {
for (int32_t dim0 = shape[0].min; dim0 < shape[0].extent + shape[0].min; ++dim0) {
counter++;
int idx[] = {dim0, dim1, dim2, dim3};
uint8_t *loc = buf->address_of(idx);
void *dst = temp + (counter - 1) * bytes_per_element;
memcpy(dst, loc, bytes_per_element);
if (counter == max_elts) {
counter = 0;
if (!f.write((void *)temp, max_elts * bytes_per_element)) {
return -13;
}
}
}
}
}
}
if (counter > 0) {
if (!f.write((void *)temp, counter * bytes_per_element)) {
return -14;
}
}
const uint64_t zero = 0;
if (final_padding_bytes) {
if (final_padding_bytes > sizeof(zero)) {
halide_error(user_context, "Unexpectedly large final_padding_bytes");
return -15;
}
if (!f.write(&zero, final_padding_bytes)) {
return -16;
}
}
return 0;
}
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

简介

MIT计算机科学和人工智能实验室的研究人员创造出一种专门设计简化图像处理的程序语言Halide,源代码托管在GitHub上,目前二进制程序只支持Mac OS X和Ubuntu 12
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C/C++
1
https://gitee.com/VisionDeveloper/Halide.git
git@gitee.com:VisionDeveloper/Halide.git
VisionDeveloper
Halide
Halide
main
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /