Skip to content

Commit 011c2ca

Browse files
authored
[SYCL][CUDA] Generalise sampler basic test (#1969)
Introduces a generic test for sycl::sampler, and moves the existing testing to the OpenCL-specific sampler_ocl.cpp.
1 parent 363ad5f commit 011c2ca

File tree

2 files changed

+61
-33
lines changed

2 files changed

+61
-33
lines changed

sycl/test/basic_tests/sampler/sampler.cpp

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
// REQUIRES: opencl
2-
31
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out -L %opencl_libs_dir -lOpenCL
42
// RUN: env SYCL_DEVICE_TYPE=HOST %t.out
53
// RUN: %CPU_RUN_PLACEHOLDER %t.out
64
// RUN: %GPU_RUN_PLACEHOLDER %t.out
7-
// RUN: %ACC_RUN_PLACEHOLDER %t.out
85

96
//==--------------- sampler.cpp - SYCL sampler basic test ------------------==//
107
//
@@ -50,37 +47,10 @@ int main() {
5047
A.get_filtering_mode() == B.get_filtering_mode());
5148

5249
// Check assignment operator
53-
if (!Queue.is_host()) {
54-
// OpenCL sampler
55-
cl_int Err = CL_SUCCESS;
56-
#ifdef CL_VERSION_2_0
57-
const cl_sampler_properties sprops[] = {
58-
CL_SAMPLER_NORMALIZED_COORDS,
59-
static_cast<cl_sampler_properties>(true),
60-
CL_SAMPLER_ADDRESSING_MODE,
61-
static_cast<cl_sampler_properties>(CL_ADDRESS_REPEAT),
62-
CL_SAMPLER_FILTER_MODE,
63-
static_cast<cl_sampler_properties>(CL_FILTER_LINEAR),
64-
0};
65-
cl_sampler ClSampler =
66-
clCreateSamplerWithProperties(Queue.get_context().get(), sprops, &Err);
67-
#else
68-
cl_sampler ClSampler =
69-
clCreateSampler(Queue.get_context().get(), true, CL_ADDRESS_REPEAT,
70-
CL_FILTER_LINEAR, &Err);
71-
#endif
72-
// If device doesn't support sampler - skip it
73-
if (Err == CL_INVALID_OPERATION)
74-
return 0;
50+
B = sycl::sampler(sycl::coordinate_normalization_mode::normalized,
51+
sycl::addressing_mode::repeat,
52+
sycl::filtering_mode::linear);
7553

76-
CHECK_OCL_CODE(Err);
77-
B = sycl::sampler(ClSampler, Queue.get_context());
78-
} else {
79-
// Host sampler
80-
B = sycl::sampler(sycl::coordinate_normalization_mode::normalized,
81-
sycl::addressing_mode::repeat,
82-
sycl::filtering_mode::linear);
83-
}
8454
assert(B.get_addressing_mode() == sycl::addressing_mode::repeat);
8555
assert(B.get_coordinate_normalization_mode() ==
8656
sycl::coordinate_normalization_mode::normalized);
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// REQUIRES: opencl
2+
3+
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out -L %opencl_libs_dir -lOpenCL
4+
// RUN: %CPU_RUN_PLACEHOLDER %t.out
5+
// RUN: %GPU_RUN_PLACEHOLDER %t.out
6+
// RUN: %ACC_RUN_PLACEHOLDER %t.out
7+
8+
//==--------------- sampler.cpp - SYCL sampler basic test ------------------==//
9+
//
10+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
11+
// See https://llvm.org/LICENSE.txt for license information.
12+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
13+
//
14+
//===----------------------------------------------------------------------===//
15+
16+
#include <CL/sycl.hpp>
17+
#include <CL/sycl/context.hpp>
18+
#include <cassert>
19+
20+
namespace sycl {
21+
using namespace cl::sycl;
22+
}
23+
24+
int main() {
25+
sycl::queue Queue;
26+
sycl::sampler B(sycl::coordinate_normalization_mode::unnormalized,
27+
sycl::addressing_mode::clamp, sycl::filtering_mode::nearest);
28+
29+
// OpenCL sampler
30+
cl_int Err = CL_SUCCESS;
31+
#ifdef CL_VERSION_2_0
32+
const cl_sampler_properties sprops[] = {
33+
CL_SAMPLER_NORMALIZED_COORDS,
34+
static_cast<cl_sampler_properties>(true),
35+
CL_SAMPLER_ADDRESSING_MODE,
36+
static_cast<cl_sampler_properties>(CL_ADDRESS_REPEAT),
37+
CL_SAMPLER_FILTER_MODE,
38+
static_cast<cl_sampler_properties>(CL_FILTER_LINEAR),
39+
0};
40+
cl_sampler ClSampler =
41+
clCreateSamplerWithProperties(Queue.get_context().get(), sprops, &Err);
42+
#else
43+
cl_sampler ClSampler =
44+
clCreateSampler(Queue.get_context().get(), true, CL_ADDRESS_REPEAT,
45+
CL_FILTER_LINEAR, &Err);
46+
#endif
47+
// If device doesn't support sampler - skip it
48+
if (Err == CL_INVALID_OPERATION)
49+
return 0;
50+
51+
CHECK_OCL_CODE(Err);
52+
B = sycl::sampler(ClSampler, Queue.get_context());
53+
54+
assert(B.get_addressing_mode() == sycl::addressing_mode::repeat);
55+
assert(B.get_coordinate_normalization_mode() ==
56+
sycl::coordinate_normalization_mode::normalized);
57+
assert(B.get_filtering_mode() == sycl::filtering_mode::linear);
58+
}

0 commit comments

Comments
 (0)