{"id":10020798,"date":"2025-05-22T18:11:02","date_gmt":"2025-05-22T10:11:02","guid":{"rendered":"https:\/\/itmax.cn\/?p=10020798"},"modified":"2025-05-22T18:11:02","modified_gmt":"2025-05-22T10:11:02","slug":"%e3%80%90triton-%e6%95%99%e7%a8%8b%e3%80%91triton_language-tensor","status":"publish","type":"post","link":"https:\/\/itmax.cn\/?p=10020798","title":{"rendered":"\u3010Triton \u6559\u7a0b\u3011triton_language.tensor"},"content":{"rendered":"<p>Triton \u662f\u4e00\u79cd\u7528\u4e8e\u5e76\u884c\u7f16\u7a0b\u7684\u8bed\u8a00\u548c\u7f16\u8bd1\u5668\u3002\u5b83\u65e8\u5728\u63d0\u4f9b\u4e00\u4e2a\u57fa\u4e8e Python \u7684\u7f16\u7a0b\u73af\u5883\uff0c\u4ee5\u9ad8\u6548\u7f16\u5199\u81ea\u5b9a\u4e49 DNN \u8ba1\u7b97\u5185\u6838\uff0c\u5e76\u80fd\u591f\u5728\u73b0\u4ee3 GPU \u786c\u4ef6\u4e0a\u4ee5\u6700\u5927\u541e\u5410\u91cf\u8fd0\u884c\u3002<br \/>\u66f4\u591a Triton \u4e2d\u6587\u6587\u6863\u53ef\u8bbf\u95ee \u2192<a href=\"https:\/\/link.segmentfault.com\/?enc=pKEvK0gi8Oa5ynRj2eseXg%3D%3D.mVtp8xQzN1%2B78KnUX78wWwDEMU8ukmKTLazgjm5SVRk%3D\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">https:\/\/triton.hyper.ai\/<\/a><\/p>\n<pre><code>class triton.language.tensor(self, handle, type: dtype)<\/code><\/pre>\n<p>\u8868\u793a\u4e00\u4e2a\u503c\u6216\u6307\u9488\u7684 N \u7ef4\u6570\u7ec4\u3002<\/p>\n<p>\u5728 Triton \u7a0b\u5e8f\u4e2d\uff0c<code>tensor<\/code>\u00a0\u662f\u6700\u57fa\u672c\u7684\u6570\u636e\u7ed3\u6784\u3002<code>triton.language<\/code>\u00a0\u4e2d\u7684\u5927\u591a\u6570\u51fd\u6570\u5bf9 tensors \u8fdb\u884c\u64cd\u4f5c\u5e76\u8fd4\u56de\u3002<\/p>\n<p>\u8fd9\u91cc\u5927\u591a\u6570\u547d\u540d\u7684\u6210\u5458\u51fd\u6570\u90fd\u662f\u00a0<code>triton.language<\/code>\u00a0\u4e2d\u81ea\u7531\u51fd\u6570\u7684\u91cd\u590d\u3002\u4f8b\u5982\uff0c<code>triton.language.sqrt(x)<\/code>\u00a0\u7b49\u540c\u4e8e\u00a0<code>x.sqrt()<\/code>\u3002<\/p>\n<p><code>tensor<\/code>\u00a0\u8fd8\u5b9a\u4e49\u4e86\u5927\u90e8\u5206\u7684\u9b54\u6cd5\/\u53cc\u4e0b\u5212\u7ebf\u65b9\u6cd5\uff0c\u56e0\u6b64\u53ef\u4ee5\u50cf\u5199\u00a0<code>x+y<\/code>\u3001<code>x &lt;&lt; 2<\/code>\u00a0\u7b49\u7b49\u3002<\/p>\n<p><strong>\u6784\u9020\u51fd\u6570<\/strong><\/p>\n<pre><code>__init__(self, handle, type: dtype)<\/code><\/pre>\n<p>\u4e0d\u88ab\u7528\u6237\u4ee3\u7801\u8c03\u7528\u3002<\/p>\n<p><strong>\u65b9\u6cd5<\/strong><\/p>\n<table>\n<thead>\n<tr>\n<th><strong>init<\/strong>(self, handle, type)<\/th>\n<th>\u4e0d\u88ab\u7528\u6237\u4ee3\u7801\u8c03\u7528<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>abs(self)<\/td>\n<td>\u8f6c\u53d1\u5230 abs() \u81ea\u7531\u51fd\u6570<\/td>\n<\/tr>\n<tr>\n<td>advance(self, offsets)<\/td>\n<td>\u8f6c\u53d1\u5230 advance() \u81ea\u7531\u51fd\u6570<\/td>\n<\/tr>\n<tr>\n<td>argmax(self, *kwargs)<\/td>\n<td>\u8f6c\u53d1\u5230 argmax() \u81ea\u7531\u51fd\u6570<\/td>\n<\/tr>\n<tr>\n<td>argmin(self, *kwargs)<\/td>\n<td>\u8f6c\u53d1\u5230 argmin() \u81ea\u7531\u51fd\u6570<\/td>\n<\/tr>\n<tr>\n<td>associative_scan(self, axis, combine_fn[, &#8230;])<\/td>\n<td>\u8f6c\u53d1\u5230 associative_scan() \u81ea\u7531\u51fd\u6570<\/td>\n<\/tr>\n<tr>\n<td>atomic_add(self, val[, mask, sem, scope])<\/td>\n<td>\u8f6c\u53d1\u5230 atomic_add() \u81ea\u7531\u51fd\u6570<\/td>\n<\/tr>\n<tr>\n<td>atomic_and(self, val[, mask, sem, scope])<\/td>\n<td>\u8f6c\u53d1\u5230 atomic_and() \u81ea\u7531\u51fd\u6570<\/td>\n<\/tr>\n<tr>\n<td>atomic_cas(self, cmp, val[, sem, scope])<\/td>\n<td>\u8f6c\u53d1\u5230 atomic_cas() \u81ea\u7531\u51fd\u6570<\/td>\n<\/tr>\n<tr>\n<td>atomic_max(self, val[, mask, sem, scope])<\/td>\n<td>\u8f6c\u53d1\u5230 atomic_max() \u81ea\u7531\u51fd\u6570<\/td>\n<\/tr>\n<tr>\n<td>atomic_min(self, val[, mask, sem, scope])<\/td>\n<td>\u8f6c\u53d1\u5230 atomic_min() \u81ea\u7531\u51fd\u6570<\/td>\n<\/tr>\n<tr>\n<td>atomic_or(self, val[, mask, sem, scope])<\/td>\n<td>\u8f6c\u53d1\u5230 atomic_or() \u81ea\u7531\u51fd\u6570<\/td>\n<\/tr>\n<tr>\n<td>atomic_xchg(self, val[, mask, sem, scope])<\/td>\n<td>\u8f6c\u53d1\u5230 atomic_xchg() \u81ea\u7531\u51fd\u6570<\/td>\n<\/tr>\n<tr>\n<td>atomic_xor(self, val[, mask, sem, scope])<\/td>\n<td>\u8f6c\u53d1\u5230 atomic_xor() \u81ea\u7531\u51fd\u6570<\/td>\n<\/tr>\n<tr>\n<td>broadcast_to(self, *shape)<\/td>\n<td>\u8f6c\u53d1\u5230 broadcast_to() \u81ea\u7531\u51fd\u6570<\/td>\n<\/tr>\n<tr>\n<td>cast(self, dtype[, fp_downcast_rounding, &#8230;])<\/td>\n<td>\u8f6c\u53d1\u5230 cast() \u81ea\u7531\u51fd\u6570<\/td>\n<\/tr>\n<tr>\n<td>cdiv(<em>self,<\/em>*kwargs)<\/td>\n<td>\u8f6c\u53d1\u5230 cdiv() \u81ea\u7531\u51fd\u6570<\/td>\n<\/tr>\n<tr>\n<td>ceil(self)<\/td>\n<td>\u8f6c\u53d1\u5230 ceil() \u81ea\u7531\u51fd\u6570<\/td>\n<\/tr>\n<tr>\n<td>cos(self)<\/td>\n<td>\u8f6c\u53d1\u5230 cos() \u81ea\u7531\u51fd\u6570<\/td>\n<\/tr>\n<tr>\n<td>cumprod(<em>self,<\/em>*kwargs)<\/td>\n<td>\u8f6c\u53d1\u5230 cumprod() \u81ea\u7531\u51fd\u6570<\/td>\n<\/tr>\n<tr>\n<td>cumsum(<em>self,<\/em>*kwargs)<\/td>\n<td>\u8f6c\u53d1\u5230 cumsum() \u81ea\u7531\u51fd\u6570<\/td>\n<\/tr>\n<tr>\n<td>erf(self)<\/td>\n<td>\u8f6c\u53d1\u5230 erf() \u81ea\u7531\u51fd\u6570<\/td>\n<\/tr>\n<tr>\n<td>exp(self)<\/td>\n<td>\u8f6c\u53d1\u5230 exp() \u81ea\u7531\u51fd\u6570<\/td>\n<\/tr>\n<tr>\n<td>exp2(self)<\/td>\n<td>\u8f6c\u53d1\u5230 exp2() \u81ea\u7531\u51fd\u6570<\/td>\n<\/tr>\n<tr>\n<td>expand_dims(self, axis)<\/td>\n<td>\u8f6c\u53d1\u5230 expand_dims() \u81ea\u7531\u51fd\u6570<\/td>\n<\/tr>\n<tr>\n<td>flip(<em>self,<\/em>*kwargs)<\/td>\n<td>\u8f6c\u53d1\u5230 flip() \u81ea\u7531\u51fd\u6570<\/td>\n<\/tr>\n<tr>\n<td>floor(self)<\/td>\n<td>\u8f6c\u53d1\u5230 floor() \u81ea\u7531\u51fd\u6570<\/td>\n<\/tr>\n<tr>\n<td>histogram(self, num_bins)<\/td>\n<td>\u8f6c\u53d1\u5230 histogram() \u81ea\u7531\u51fd\u6570<\/td>\n<\/tr>\n<tr>\n<td>log(self)<\/td>\n<td>\u8f6c\u53d1\u5230 log() \u81ea\u7531\u51fd\u6570<\/td>\n<\/tr>\n<tr>\n<td>log2(self)<\/td>\n<td>\u8f6c\u53d1\u5230 log2() \u81ea\u7531\u51fd\u6570<\/td>\n<\/tr>\n<tr>\n<td>logical_and(self, other)<\/td>\n<td> <\/td>\n<\/tr>\n<tr>\n<td>logical_or(self, other)<\/td>\n<td> <\/td>\n<\/tr>\n<tr>\n<td>max(<em>self,<\/em>*kwargs)<\/td>\n<td>\u8f6c\u53d1\u5230 max() \u81ea\u7531\u51fd\u6570<\/td>\n<\/tr>\n<tr>\n<td>min(<em>self,<\/em>*kwargs)<\/td>\n<td>\u8f6c\u53d1\u5230 min() \u81ea\u7531\u51fd\u6570<\/td>\n<\/tr>\n<tr>\n<td>permute(self, *dims)<\/td>\n<td>\u8f6c\u53d1\u5230 permute() \u81ea\u7531\u51fd\u6570<\/td>\n<\/tr>\n<tr>\n<td>ravel(<em>self,<\/em>*kwargs)<\/td>\n<td>\u8f6c\u53d1\u5230 ravel() \u81ea\u7531\u51fd\u6570<\/td>\n<\/tr>\n<tr>\n<td>reduce(self, axis, combine_fn[, keep_dims])<\/td>\n<td>\u8f6c\u53d1\u5230 reduce() \u81ea\u7531\u51fd\u6570<\/td>\n<\/tr>\n<tr>\n<td>reshape(self, *shape[, can_reorder])<\/td>\n<td>\u8f6c\u53d1\u5230 reshape() \u81ea\u7531\u51fd\u6570<\/td>\n<\/tr>\n<tr>\n<td>rsqrt(self)<\/td>\n<td>\u8f6c\u53d1\u5230 rsqrt() \u81ea\u7531\u51fd\u6570<\/td>\n<\/tr>\n<tr>\n<td>sigmoid(<em>self,<\/em>*kwargs)<\/td>\n<td>\u8f6c\u53d1\u5230 sigmoid() \u81ea\u7531\u51fd\u6570<\/td>\n<\/tr>\n<tr>\n<td>sin(self)<\/td>\n<td>\u8f6c\u53d1\u5230 sin() \u81ea\u7531\u51fd\u6570<\/td>\n<\/tr>\n<tr>\n<td>softmax(<em>self,<\/em>*kwargs)<\/td>\n<td>\u8f6c\u53d1\u5230 softmax() \u81ea\u7531\u51fd\u6570<\/td>\n<\/tr>\n<tr>\n<td>sort(<em>self,<\/em>*kwargs)<\/td>\n<td>\u8f6c\u53d1\u5230 sort() \u81ea\u7531\u51fd\u6570<\/td>\n<\/tr>\n<tr>\n<td>split(self)<\/td>\n<td>\u8f6c\u53d1\u5230 split() \u81ea\u7531\u51fd\u6570<\/td>\n<\/tr>\n<tr>\n<td>sqrt(self)<\/td>\n<td>\u8f6c\u53d1\u5230 sqrt() \u81ea\u7531\u51fd\u6570<\/td>\n<\/tr>\n<tr>\n<td>sqrt_rn(self)<\/td>\n<td>\u8f6c\u53d1\u5230 sqrt_rn() \u81ea\u7531\u51fd\u6570<\/td>\n<\/tr>\n<tr>\n<td>store(self, value[, mask, boundary_check, &#8230;])<\/td>\n<td>\u8f6c\u53d1\u5230 store() \u81ea\u7531\u51fd\u6570<\/td>\n<\/tr>\n<tr>\n<td>sum(<em>self,<\/em>*kwargs)<\/td>\n<td>\u8f6c\u53d1\u5230 sum() \u81ea\u7531\u51fd\u6570<\/td>\n<\/tr>\n<tr>\n<td>to(self, dtype[, fp_downcast_rounding, bitcast])<\/td>\n<td>tensor.cast() \u7684\u522b\u540d<\/td>\n<\/tr>\n<tr>\n<td>trans(self, *dims)<\/td>\n<td>\u8f6c\u53d1\u5230 trans() \u81ea\u7531\u51fd\u6570<\/td>\n<\/tr>\n<tr>\n<td>view(self, *shape)<\/td>\n<td>\u8f6c\u53d1\u5230 view() \u81ea\u7531\u51fd\u6570<\/td>\n<\/tr>\n<tr>\n<td>xor_sum(self[, axis, keep_dims])<\/td>\n<td>\u8f6c\u53d1\u5230 xor_sum() \u81ea\u7531\u51fd\u6570<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>\u5c5e\u6027<\/strong><\/p>\n<table>\n<thead>\n<tr>\n<th>T<\/th>\n<th>\u8f6c\u7f6e 1 \u4e2a 2D \u5f20\u91cf<\/th>\n<\/tr>\n<\/thead>\n<\/tbody>\n<\/table>\n<p><a href=\"https:\/\/segmentfault.com\/a\/1190000046556478\">https:\/\/segmentfault.com\/a\/1190000046556478<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Triton \u662f\u4e00\u79cd\u7528\u4e8e\u5e76\u884c\u7f16\u7a0b\u7684\u8bed\u8a00\u548c\u7f16\u8bd1\u5668\u3002\u5b83\u65e8\u5728\u63d0\u4f9b\u4e00\u4e2a\u57fa\u4e8e Python \u7684\u7f16\u7a0b\u73af\u5883\uff0c\u4ee5\u9ad8\u6548\u7f16\u5199\u81ea\u5b9a\u4e49 [&hellip;]<\/p>\n","protected":false},"author":7,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4],"tags":[],"class_list":["post-10020798","post","type-post","status-publish","format-standard","hentry","category-share"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10020798","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10020798"}],"version-history":[{"count":0,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10020798\/revisions"}],"wp:attachment":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10020798"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10020798"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10020798"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}