Skip to content

Commit ebff19a

Browse files
Added lit test case for all cuTensor APIs
1 parent 8513308 commit ebff19a

1 file changed

Lines changed: 215 additions & 0 deletions

File tree

clang/test/dpct/cutensor.cu

Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
1+
// RUN: dpct --format-range=none --out-root=%T/cutensor %s --cuda-include-path="%cuda-path/include"
2+
// RUN: FileCheck %s --match-full-lines --input-file %T/cutensor/cutensor.dp.cpp
3+
#include <cstdio>
4+
#include <cutensor.h>
5+
#include <cutensorMg.h>
6+
7+
int main() {
8+
cudaStream_t stream;
9+
10+
// Basic handle creation and destruction
11+
cutensorHandle_t handle;
12+
// CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorCreate is not supported.
13+
cutensorCreate(&handle);
14+
// CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorDestroy is not supported.
15+
cutensorDestroy(handle);
16+
17+
// Tensor descriptor
18+
cutensorTensorDescriptor_t tensorDesc;
19+
uint32_t numModes = 0;
20+
int64_t *extent;
21+
int64_t *stride;
22+
cutensorDataType_t tensorDataType;
23+
uint32_t alignmentRequirement;
24+
// CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorCreateTensorDescriptor is not supported.
25+
cutensorCreateTensorDescriptor(handle, &tensorDesc, numModes, extent, stride, tensorDataType, alignmentRequirement);
26+
// CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorDestroyTensorDescriptor is not supported.
27+
cutensorDestroyTensorDescriptor(tensorDesc);
28+
29+
// Get cuTENSOR versions and error strings
30+
// CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorGetErrorString is not supported.
31+
const char *errStr = cutensorGetErrorString(CUTENSOR_STATUS_SUCCESS);
32+
printf("Error String: %s\n", errStr);
33+
// CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorGetVersion is not supported.
34+
int version = cutensorGetVersion();
35+
// CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorGetCudartVersion is not supported.
36+
int cudartVer = cutensorGetCudartVersion();
37+
printf("cuTENSOR Version: %d, CUDA Runtime Version: %d\n", version, cudartVer);
38+
39+
// Elementwise trinary operations
40+
cutensorOperationDescriptor_t opDesc;
41+
int32_t *modes;
42+
cutensorOperator_t op;
43+
cutensorComputeDescriptor_t descCompute;
44+
cutensorPlan_t plan;
45+
const void *alpha, *A, *beta, *B, *gamma, *C;
46+
void *D;
47+
// CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorCreateElementwiseTrinary is not supported.
48+
cutensorCreateElementwiseTrinary(handle, &opDesc, tensorDesc, modes, op, tensorDesc, modes, op, tensorDesc, modes, op, tensorDesc, modes, op, op, descCompute);
49+
// CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorElementwiseTrinaryExecute is not supported.
50+
cutensorElementwiseTrinaryExecute(handle, plan, alpha, A, beta, B, gamma, C, D, stream);
51+
52+
// Elementwise binary operations
53+
// CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorCreateElementwiseBinary is not supported.
54+
cutensorCreateElementwiseBinary(handle, &opDesc, tensorDesc, modes, op, tensorDesc, modes, op, tensorDesc, modes, op, descCompute);
55+
// CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorElementwiseBinaryExecute is not supported.
56+
cutensorElementwiseBinaryExecute(handle, plan, alpha, A, gamma, C, D, stream);
57+
58+
// Permutation
59+
// CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorCreatePermutation is not supported.
60+
cutensorCreatePermutation(handle, &opDesc, tensorDesc, modes, op, tensorDesc, modes, descCompute);
61+
// CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorPermute is not supported.
62+
cutensorPermute(handle, plan, alpha, A, D, stream);
63+
64+
// Contraction
65+
void *workspace;
66+
uint64_t workspaceSize;
67+
// CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorCreateContraction is not supported.
68+
cutensorCreateContraction(handle, &opDesc, tensorDesc, modes, op, tensorDesc, modes, op, tensorDesc, modes, op, tensorDesc, modes, descCompute);
69+
// CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorContract is not supported.
70+
cutensorContract(handle, plan, alpha, A, B, beta, C, D, workspace, workspaceSize, stream);
71+
72+
// Contraction Trinary
73+
// CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorCreateContractionTrinary is not supported.
74+
cutensorCreateContractionTrinary(handle, &opDesc, tensorDesc, modes, op, tensorDesc, modes, op, tensorDesc, modes, op, tensorDesc, modes, op, tensorDesc, modes, descCompute);
75+
// CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorContractTrinary is not supported.
76+
cutensorContractTrinary(handle, plan, alpha, A, B, C, beta, C, D, workspace, workspaceSize, stream);
77+
78+
// Reduction
79+
// CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorCreateReduction is not supported.
80+
cutensorCreateReduction(handle, &opDesc, tensorDesc, modes, op, tensorDesc, modes, op, tensorDesc, modes, op, descCompute);
81+
// CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorReduce is not supported.
82+
cutensorReduce(handle, plan, alpha, A, beta, C, D, workspace, workspaceSize, stream);
83+
84+
// Operation descriptor functions
85+
// CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorDestroyOperationDescriptor is not supported.
86+
cutensorDestroyOperationDescriptor(opDesc);
87+
cutensorOperationDescriptorAttribute_t opAttr;
88+
void *buf;
89+
size_t sizeInBytes;
90+
// CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorOperationDescriptorGetAttribute is not supported.
91+
cutensorOperationDescriptorGetAttribute(handle, opDesc, opAttr, buf, sizeInBytes);
92+
// CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorOperationDescriptorSetAttribute is not supported.
93+
cutensorOperationDescriptorSetAttribute(handle, opDesc, opAttr, buf, sizeInBytes);
94+
95+
// Plan preference functions
96+
cutensorPlanPreference_t planPref;
97+
cutensorPlanPreferenceAttribute_t planPrefAttr;
98+
cutensorAlgo_t algo;
99+
cutensorJitMode_t jitMode;
100+
cutensorWorksizePreference_t workspacePref;
101+
uint64_t *workspaceSizeEstimate;
102+
// CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorCreatePlanPreference is not supported.
103+
cutensorCreatePlanPreference(handle, &planPref, algo, jitMode);
104+
// CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorDestroyPlanPreference is not supported.
105+
cutensorDestroyPlanPreference(planPref);
106+
// CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorPlanPreferenceSetAttribute is not supported.
107+
cutensorPlanPreferenceSetAttribute(handle, planPref, planPrefAttr, buf, sizeInBytes);
108+
// CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorEstimateWorkspaceSize is not supported.
109+
cutensorEstimateWorkspaceSize(handle, opDesc, planPref, workspacePref, workspaceSizeEstimate);
110+
cutensorPlanAttribute_t planAttr;
111+
// CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorCreatePlan is not supported.
112+
cutensorCreatePlan(handle, &plan, opDesc, planPref, *workspaceSizeEstimate);
113+
// CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorDestroyPlan is not supported.
114+
cutensorDestroyPlan(plan);
115+
// CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorPlanGetAttribute is not supported.
116+
cutensorPlanGetAttribute(handle, plan, planAttr, buf, sizeInBytes);
117+
118+
// Plan cache management
119+
uint32_t numCachelinesRead;
120+
// CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorHandleResizePlanCache is not supported.
121+
cutensorHandleResizePlanCache(handle, 0);
122+
// CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorHandleReadPlanCacheFromFile is not supported.
123+
cutensorHandleReadPlanCacheFromFile(handle, "plan_cache.dat", &numCachelinesRead);
124+
// CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorHandleWritePlanCacheToFile is not supported.
125+
cutensorHandleWritePlanCacheToFile(handle, "plan_cache.dat");
126+
// CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorReadKernelCacheFromFile is not supported.
127+
cutensorReadKernelCacheFromFile(handle, "kernel_cache.dat");
128+
// CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorWriteKernelCacheToFile is not supported.
129+
cutensorWriteKernelCacheToFile(handle, "kernel_cache.dat");
130+
131+
// Logger functions
132+
cutensorLoggerCallback_t callback;
133+
FILE *file;
134+
// CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorLoggerSetCallback is not supported.
135+
cutensorLoggerSetCallback(callback);
136+
// CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorLoggerSetFile is not supported.
137+
cutensorLoggerSetFile(file);
138+
// CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorLoggerOpenFile is not supported.
139+
cutensorLoggerOpenFile("logfile.txt");
140+
// CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorLoggerSetLevel is not supported.
141+
cutensorLoggerSetLevel(0);
142+
// CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorLoggerSetMask is not supported.
143+
cutensorLoggerSetMask(0);
144+
// CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorLoggerForceDisable is not supported.
145+
cutensorLoggerForceDisable();
146+
147+
// Multi-grid (Mg) APIs
148+
// Mg handle creation and destruction
149+
cutensorMgHandle_t mgHandle;
150+
uint32_t numDevices;
151+
const int32_t *devices;
152+
// CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorMgCreate is not supported.
153+
cutensorMgCreate(&mgHandle, numDevices, devices);
154+
// CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorMgDestroy is not supported.
155+
cutensorMgDestroy(mgHandle);
156+
157+
// Mg tensor descriptor
158+
cutensorMgTensorDescriptor_t *desc;
159+
const int64_t *blockSize;
160+
const int32_t *deviceCount;
161+
cudaDataType_t dataType;
162+
cutensorMgTensorDescriptor_t mgTensorDesc;
163+
// CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorMgCreateTensorDescriptor is not supported.
164+
cutensorMgCreateTensorDescriptor(mgHandle, &mgTensorDesc, numModes, extent, stride, blockSize, stride, deviceCount, numDevices, devices, dataType);
165+
// CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorMgDestroyTensorDescriptor is not supported.
166+
cutensorMgDestroyTensorDescriptor(mgTensorDesc);
167+
168+
// Mg copy descriptor & plan
169+
cutensorMgCopyDescriptor_t mgCopyDesc;
170+
// CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorMgCreateCopyDescriptor is not supported.
171+
cutensorMgCreateCopyDescriptor(mgHandle, &mgCopyDesc, mgTensorDesc, modes, mgTensorDesc, modes);
172+
// CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorMgDestroyCopyDescriptor is not supported.
173+
cutensorMgDestroyCopyDescriptor(mgCopyDesc);
174+
int64_t hostWorkspaceSize = 0;
175+
int64_t *deviceWorkspaceSize;
176+
// CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorMgCopyGetWorkspace is not supported.
177+
cutensorMgCopyGetWorkspace(mgHandle, mgCopyDesc, deviceWorkspaceSize, &hostWorkspaceSize);
178+
cutensorMgCopyPlan_t mgCopyPlan;
179+
// CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorMgCreateCopyPlan is not supported.
180+
cutensorMgCreateCopyPlan(mgHandle, &mgCopyPlan, mgCopyDesc, deviceWorkspaceSize, hostWorkspaceSize);
181+
// CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorMgDestroyCopyPlan is not supported.
182+
cutensorMgDestroyCopyPlan(mgCopyPlan);
183+
void *ptrDst;
184+
const void *ptrSrc;
185+
void *deviceWorkspace;
186+
void *hostWorkspace;
187+
cudaStream_t *streams;
188+
// CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorMgCopy is not supported.
189+
cutensorMgCopy(mgHandle, mgCopyPlan, &ptrDst, &ptrSrc, &deviceWorkspace, hostWorkspace, streams);
190+
191+
// Mg contraction descriptor, find, plan, and execution
192+
cutensorMgContractionDescriptor_t mgContrDesc;
193+
cutensorComputeType_t computeType;
194+
// CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorMgCreateContractionDescriptor is not supported.
195+
cutensorMgCreateContractionDescriptor(mgHandle, &mgContrDesc, mgTensorDesc, modes, mgTensorDesc, modes, mgTensorDesc, modes, mgTensorDesc, modes, computeType);
196+
// CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorMgDestroyContractionDescriptor is not supported.
197+
cutensorMgDestroyContractionDescriptor(mgContrDesc);
198+
cutensorMgContractionFind_t mgContrFind;
199+
cutensorMgAlgo_t mgAlgo;
200+
// CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorMgCreateContractionFind is not supported.
201+
cutensorMgCreateContractionFind(mgHandle, &mgContrFind, mgAlgo);
202+
// CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorMgDestroyContractionFind is not supported.
203+
cutensorMgDestroyContractionFind(mgContrFind);
204+
// CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorMgContractionGetWorkspace is not supported.
205+
cutensorMgContractionGetWorkspace(mgHandle, mgContrDesc, mgContrFind, workspacePref, deviceWorkspaceSize, &hostWorkspaceSize);
206+
cutensorMgContractionPlan_t mgContrPlan;
207+
// CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorMgCreateContractionPlan is not supported.
208+
cutensorMgCreateContractionPlan(mgHandle, &mgContrPlan, mgContrDesc, mgContrFind, deviceWorkspaceSize, hostWorkspaceSize);
209+
// CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorMgDestroyContractionPlan is not supported.
210+
cutensorMgDestroyContractionPlan(mgContrPlan);
211+
// CHECK: DPCT1007:{{[0-9]+}}: Migration of cutensorMgContraction is not supported.
212+
cutensorMgContraction(mgHandle, mgContrPlan, alpha, &A, &B, beta, &C, &D, &deviceWorkspace, hostWorkspace, streams);
213+
214+
return 0;
215+
}

0 commit comments

Comments
 (0)