-
Notifications
You must be signed in to change notification settings - Fork 756
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SYCL][USM] Fix bug with malloc(..., kind) impl and host allocations (#…
…691) Also rename host-only alignedAlloc to be less ambiguous Signed-off-by: James Brodman <james.brodman@intel.com>
- Loading branch information
1 parent
b207160
commit 01869a0
Showing
4 changed files
with
98 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// RUN: %clangxx -fsycl %s -o %t1.out | ||
// RUN: env SYCL_DEVICE_TYPE=HOST %t1.out | ||
// RUN: %CPU_RUN_PLACEHOLDER %t1.out | ||
// RUN: %GPU_RUN_PLACEHOLDER %t1.out | ||
|
||
//==------------------- mixed2.cpp - Mixed Memory test ---------------------==// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include <CL/sycl.hpp> | ||
|
||
using namespace cl::sycl; | ||
|
||
class foo; | ||
int main() { | ||
int *darray = nullptr; | ||
int *sarray = nullptr; | ||
int *harray = nullptr; | ||
const int N = 4; | ||
const int MAGIC_NUM = 42; | ||
|
||
queue q; | ||
auto dev = q.get_device(); | ||
auto ctxt = q.get_context(); | ||
|
||
darray = (int *)malloc(N * sizeof(int), dev, ctxt, usm::alloc::device); | ||
if (darray == nullptr) { | ||
return -1; | ||
} | ||
sarray = (int *)malloc(N * sizeof(int), dev, ctxt, usm::alloc::shared); | ||
|
||
if (sarray == nullptr) { | ||
return -1; | ||
} | ||
|
||
harray = (int *)malloc(N * sizeof(int), dev, ctxt, usm::alloc::host); | ||
if (harray == nullptr) { | ||
return -1; | ||
} | ||
for (int i = 0; i < N; i++) { | ||
sarray[i] = MAGIC_NUM - 1; | ||
harray[i] = 1; | ||
} | ||
|
||
auto e0 = q.memset(darray, 0, N * sizeof(int)); | ||
e0.wait(); | ||
|
||
auto e1 = q.submit([=](handler &cgh) { | ||
cgh.single_task<class foo>([=]() { | ||
for (int i = 0; i < N; i++) { | ||
sarray[i] += darray[i] + harray[i]; | ||
} | ||
}); | ||
}); | ||
|
||
e1.wait(); | ||
|
||
for (int i = 0; i < N; i++) { | ||
if (sarray[i] != MAGIC_NUM) { | ||
return -1; | ||
} | ||
} | ||
free(darray, ctxt); | ||
free(sarray, ctxt); | ||
free(harray, ctxt); | ||
|
||
return 0; | ||
} |