본문으로 건너뛰기
Skillpedia
일반 코딩5.8k · #14557

vectorization

하는 일

이 스킬은 한 번에 여러 값을 처리하는 SIMD로 .NET 코드를 최적화하면서, 결과는 원래 코드와 같게 유지하도록 돕습니다. 성능이 중요한 숫자 계산 코드를 가진 .NET 개발자를 위한 스킬입니다.

사용하는 경우

  • ✓.NET의 숫자 반복문이 느려서 벡터 코드로 속도를 높이고 싶을 때.
  • ✓기존 SIMD 코드가 올바른지, 다른 환경에서도 되는지 검토하고 싶을 때.
  • ✓TensorPrimitives나 하드웨어 인트린직을 안전하게 쓰고 싶을 때.

스킬 링크

https://github.com/dotnet/skills/blob/main/plugins/dotnet-advanced/skills/vectorization/SKILL.md

복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.

사용 방법

가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

Use this skill to help me: https://github.com/dotnet/skills/blob/main/plugins/dotnet-advanced/skills/vectorization/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

AI에게 요청하는 예시

“큰 float 배열을 더하고 곱하는 이 .NET 함수를 벡터화하고, 결과가 원래 함수와 같은지 확인해 주세요.”

매주 새 스킬 5개. 읽는 데 1분.

작동 방식

에이전트가 스칼라 버전을 기준으로 남기고, 남은 항목을 올바르게 처리하는 벡터 버전을 작성하고, 결과가 같은지 테스트한 뒤 속도를 측정해 받아들일지 정합니다.

기술 내용 (원본 SKILL.md)

작성자의 영어 원문을 GitHub에서 그대로 가져왔습니다.

.NET SIMD vectorization

Produce a portable optimization that preserves the scalar contract, remains memory-safe at every length, and earns its complexity with measured results. Read the official SIMD and hardware-intrinsics guidance first and follow its comprehensive implementation templates. In particular, use its self-contained per-width dispatch, dedicated small-input handling, loop, and remainder shapes rather than reducing them to a chain of width checks. This skill supplies the decision rules and validation checks to apply while changing real code.

Inputs and prerequisites

Discover these from the repository before asking the user:

Input Required What to establish
Scalar implementation and tests Yes Existing contract, representative call sites, and supported overlap
Target frameworks and platforms Yes Available SIMD APIs and architectures that must behave consistently
Build and test workflow Yes The repository's normal commands and how to launch separate test processes
Representative workload or benchmark For optimization Typical input sizes and the baseline to beat

Do not add a package merely because an API exists there. First check the target framework and the project's existing dependency/versioning policy.

Core rules

  1. Use the highest-level API that matches the contract, then stop. Span<T> and string operations, TensorPrimitives, and tensor types already accelerate many operations. LINQ reductions such as Sum, Min, Max, and Average can also accelerate when the source exposes its underlying span. Verify empty-input and floating-point behavior rather than assuming similarly named operations are interchangeable. Once an existing API preserves the contract, use it instead of continuing into handwritten SIMD. Before writing an explicit loop, name the framework APIs considered and why none applies. Fixed-shape System.Numerics types remain appropriate for graphics and similar domains.
  2. Start new explicit SIMD loops with Vector128<T>. It is accelerated across the broadest hardware set. Add wider fixed-width paths only when measurements justify them.
  3. Keep platforms consistent. Prefer cross-platform operations on the fixed-width vector types; they lower to the appropriate target instructions. For example, (vector & mask) == Vector128<byte>.Zero becomes ptest on x86/x64. Use architecture-specific intrinsics only for a measured gap, guard them with IsSupported, and retain equivalent portable or scalar behavior.
  4. Read IsHardwareAccelerated, IsSupported, and Count directly. The JIT treats them as constants, so caching them adds no value and obscures which branches disappear.
  5. Prefer operators where they are clear. Parenthesize expressions that mix bitwise and comparison operators so precedence is explicit.

If the task is review-only, do not rewrite the code. Report correctness and memory-safety defects before performance opportunities.

Authoring checklist

  • Contract: identify behavior for empty and short inputs, overlap, overflow, NaN, signed zero, ordering, and exceptions before changing the implementation.
  • Framework gate: inspect the target framework and existing package references, then compile or probe the highest-level candidate API with the required edge cases. A small contract adapter, such as preserving special empty-input behavior, does not justify reimplementing the operation. If the API preserves the contract, use it and stop; do not claim it is unavailable without checking.
  • Structure: for new explicit SIMD, implement Vector128<T> and scalar first. Only after measurements justify wider paths, check Vector512<T>, then Vector256<T>, optional Vector<T>, Vector128<T>, and finally scalar. Omit paths the implementation does not need. Each outer fixed-width guard checks only its IsHardwareAccelerated property and, for generic element types, IsSupported. Inside that block, run the width-specific helper when the input has at least Count elements; otherwise run a dedicated small-input helper, then return. Do not put the length check in the outer guard and fall through to repeat dispatch at narrower widths. Keeping each supported-width block self-contained lets the JIT remove unsupported blocks and avoids redundant work on common sm
자주 묻는 질문

결과가 바뀌나요?

아니요. 목표는 테스트로 확인한 스칼라 코드와 같은 결과를 유지하는 것입니다.

코드를 항상 빠르게 만드나요?

아니요. 측정 결과 복잡도를 감수할 만큼 효과가 있을 때만 최적화를 유지합니다.

어떤 플랫폼을 다루나요?

이식 가능한 벡터 API와 여러 아키텍처의 하드웨어 전용 인트린직을 다룹니다.

상세 정보

작성자의 원본 설명

Design, implement, optimize, and review SIMD code in .NET. USE FOR: vectorizing scalar loops with TensorPrimitives, Vector64/128/256/512, or platform hardware intrinsics; reviewing existing SIMD code, including the generic Vector type, for contract equivalence, tail handling, memory safety, portability, fallbacks, and measured performance. DO NOT USE FOR: performance work unrelated to SIMD or vectorization.

repo: dotnet/skills

인기도

GitHub 스타
5.8k
순위
#14557
라이선스
MIT
업데이트
2026. 11. 2.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬